Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions tools/wasm/src_js/sync/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,14 @@ class Connection {
execute(preparedStatement, params = {}) {
this._checkConnection();
if (!preparedStatement ||
typeof preparedStatement !== "object" ||
preparedStatement.constructor.name !== "PreparedStatement" ||
preparedStatement._isClosed) {
throw new Error("preparedStatement must be a valid PreparedStatement object.");
throw new Error("preparedStatement is not valid or is closed.");
}
Comment on lines 127 to 130
Copy link
Preview

Copilot AI May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The error message for an invalid or closed PreparedStatement is now combined; consider splitting the checks for a more granular error message to make debugging easier.

Copilot uses AI. Check for mistakes.

if (!preparedStatement.isSuccess()) {
throw new Error(preparedStatement.getErrorMessage());
}
if (params.constructor.name !== "Object") {
throw new Error("params must be a plain object.");
if (!params) {
throw new Error("params is not valid.");
}
const paramsArray = [];
for (const key in params) {
Expand Down
8 changes: 4 additions & 4 deletions tools/wasm/test/test_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ describe("Execute", function () {
}
});

it("should throw error if the parameters is not a plain object", async function () {
it("should throw error if the parameters is null", async function () {
try {
const preparedStatement = await conn.prepare(
"MATCH (a:person) WHERE a.ID = $1 RETURN COUNT(*)"
);
assert.exists(preparedStatement);
assert.isTrue(preparedStatement.isSuccess());
await conn.execute(preparedStatement, []);
assert.fail("No error thrown when params is not a plain object.");
await conn.execute(preparedStatement, null);
assert.fail("No error thrown when params is null.");
} catch (e) {
assert.equal(e.message, "params must be a plain object.");
assert.equal(e.message, "params is not valid.");
}
});
});
Expand Down
Loading