Skip to content

Vs Code db2i SQLRunnerTool issue on alias creation #562

Description

@crisrivlop

Title: vscode-db2i-chat-sqlRunnerTool crashes with Cannot read properties of undefined (reading 'length') when executing DDL statements

Labels: bug


Describe the bug

When executing DDL statements (e.g., CREATE ALIAS, CREATE TABLE, DROP TABLE) through the vscode-db2i-chat-sqlRunnerTool Copilot tool, the extension crashes with:

Cannot read properties of undefined (reading 'length')
(at tsx element FF > NU > sGe > hxt > dl > <anonymous> > <anonymous> > WSt > Axt > n0)

The statement does execute successfully on the server, but the tool throws before returning a result, which causes the Copilot agent to treat the call as failed and abort its workflow.

Root cause

In src/aiProviders/copilot/sqlTool.ts, the result is serialized unconditionally:

const result = await JobManager.runSQL(trimmed);
return new LanguageModelToolResult([new LanguageModelTextPart(JSON.stringify(result))]);

DDL statements do not return a result set, so runSQL() returns undefined. In JavaScript, JSON.stringify(undefined) evaluates to undefined (not the string "undefined"), and passing undefined to LanguageModelTextPart causes the crash when the VS Code language model infrastructure reads .length on the value.

Steps to reproduce

  1. Open a Copilot Chat with a DB2 for i connection active.
  2. Ask the agent to run a DDL statement, e.g.:
    CREATE OR REPLACE ALIAS MYLIB.TEST_ALIAS FOR SYSIBM.SYSDUMMY1
  3. Observe the empty Output field in the tool call UI, followed by the error above.

Expected behavior

The tool should return a success message (e.g., "Statement executed successfully.") when runSQL() returns undefined, instead of crashing.

Suggested fix

const result = await JobManager.runSQL(trimmed);
const output = result !== undefined
  ? JSON.stringify(result)
  : 'Statement executed successfully (no result set returned).';
return new LanguageModelToolResult([new LanguageModelTextPart(output)]);

Environment

  • Extension: vscode-db2i (codefori)
  • VS Code: with GitHub Copilot Chat
  • Affected file: src/aiProviders/copilot/sqlTool.ts
  • Affected tool ID: vscode-db2i-chat-sqlRunnerTool

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions