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
- Open a Copilot Chat with a DB2 for i connection active.
- Ask the agent to run a DDL statement, e.g.:
CREATE OR REPLACE ALIAS MYLIB.TEST_ALIAS FOR SYSIBM.SYSDUMMY1
- 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
Title:
vscode-db2i-chat-sqlRunnerToolcrashes withCannot read properties of undefined (reading 'length')when executing DDL statementsLabels:
bugDescribe the bug
When executing DDL statements (e.g.,
CREATE ALIAS,CREATE TABLE,DROP TABLE) through thevscode-db2i-chat-sqlRunnerToolCopilot tool, the extension crashes with: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:DDL statements do not return a result set, so
runSQL()returnsundefined. In JavaScript,JSON.stringify(undefined)evaluates toundefined(not the string"undefined"), and passingundefinedtoLanguageModelTextPartcauses the crash when the VS Code language model infrastructure reads.lengthon the value.Steps to reproduce
Outputfield in the tool call UI, followed by the error above.Expected behavior
The tool should return a success message (e.g.,
"Statement executed successfully.") whenrunSQL()returnsundefined, instead of crashing.Suggested fix
Environment
vscode-db2i(codefori)src/aiProviders/copilot/sqlTool.tsvscode-db2i-chat-sqlRunnerTool