Skip to content

Commit

Permalink
Fix multi-statement error handling in node query result (#3340)
Browse files Browse the repository at this point in the history
  • Loading branch information
mewim committed Apr 22, 2024
1 parent 9594367 commit e171061
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/nodejs_api/src_cpp/include/node_query_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ class NodeQueryResultGetNextQueryResultAsyncWorker : public Napi::AsyncWorker {
void Execute() override {
try {
auto nextResult = currQueryResult->queryResult->getNextQueryResult();
if (!nextResult->isSuccess()) {
SetError(nextResult->getErrorMessage());
return;
}
nextQueryResult->SetQueryResult(nextResult, false);
} catch (const std::exception& exc) {
SetError(std::string(exc.what()));
Expand Down
14 changes: 14 additions & 0 deletions tools/nodejs_api/test/test_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@ describe("Query", function () {
]);
assert.deepEqual(results, [[{ 1: 1 }], [{ 2: 2 }], [{ 3: 3 }]]);
});

it("should throw error if one of the multiple queries is invalid", async function () {
try {
await conn.query(`
RETURN 1;
RETURN 2;
MATCH (a:dog) RETURN COUNT(*);
`);
assert.fail("No error thrown when one of the multiple queries is invalid.");
} catch (e) {
assert.equal(e.message, "Binder exception: Table dog does not exist.");
}
}
);
});

describe("Timeout", function () {
Expand Down

0 comments on commit e171061

Please sign in to comment.