Skip to content

Commit 5a91a98

Browse files
jeffreyavenclaude
andcommitted
Handle empty (null) query result without crashing
stackql emits the literal `null` for a query that matches no rows. assertResult parsed that to null and then read `.length` on it, throwing "Cannot read properties of null (reading 'length')" instead of reporting a clean assertion failure. Normalise a non-array parsed result to an empty array so a 0-rows-vs-expected case fails with a readable message. Adds coverage. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent cf5b39e commit 5a91a98

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎lib/assert.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ function assertResult(core) {
5656
// if no EXPECTED_RESULTS_STR, EXPECTED_RESULTS_FILE_PATH or EXPECTED_ROWS, fail the action
5757
if (!EXPECTED_RESULTS_STR && !EXPECTED_RESULTS_FILE_PATH && !EXPECTED_ROWS) throw new Error("❌ Cannot find expected result, file path or expected rows");
5858

59-
const actualResult = parseResult(RESULT);
59+
// stackql emits the literal `null` for a query that matches no rows;
60+
// normalise that (and any non-array result) to an empty array so an
61+
// empty result set is a clean assertion failure, not a crash on .length.
62+
const parsed = parseResult(RESULT);
63+
const actualResult = Array.isArray(parsed) ? parsed : [];
6064

6165
core.info("🔍 Checking results...");
6266

‎lib/tests/assert.test.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ describe('assertResult', ()=>{
185185
expect(coreObj.info).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Successful'))
186186
})
187187

188+
it('it should fail cleanly (not crash) when the query returns null and rows are expected', ()=>{
189+
// stackql emits the literal `null` for an empty result set
190+
process.env.RESULT = 'null'
191+
process.env.EXPECTED_RESULTS_STR = undefined;
192+
process.env.EXPECTED_RESULTS_FILE_PATH = undefined;
193+
process.env.EXPECTED_ROWS = 1
194+
195+
assertResult(coreObj)
188196

197+
expect(coreObj.setFailed).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Failed'))
198+
expect(coreObj.error).toHaveBeenCalledWith('Expected rows: 1, got: 0')
199+
})
189200

190201
})

0 commit comments

Comments
 (0)