codefori / codefori/vscode-db2i
Vs Code db2i SQLRunnerTool issue on alias creation
- Dominant language
- TypeScript
- Stars
- 76
- Forks
- 54
- Avg merge
- 17m
- Merged PRs (30d)
- 1
Description
---
**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 > > > 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:
```typescript
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.:
```sql
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**
```typescript
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`
---
Contributor guide
No contributing guide indexed for this repository
Research direction
Read src/aiProviders/copilot/sqlTool.ts and follow the SQL runner path described in the issue, then reproduce the behavior with a DDL statement such as CREATE OR REPLACE ALIAS. Done means DDL calls return a text success message when no result set is returned, while statements with results continue to return their serialized output without crashing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vscode
- Domain
- database, devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100