nolanlawson / node-websql

The WebSQL Database API, implemented for Node.js
Apache License 2.0
89 stars 36 forks source link

Errors thrown from async statement success callbacks are not treated as per spec #40

Closed DerGuteMoritz closed 3 years ago

DerGuteMoritz commented 3 years ago

Given the following code:

const openDatabase = require("websql");

const db = openDatabase(":memory:", "1.0", "test", 1);

try {
  db.transaction(txn => {
    console.log(1);
    txn.executeSql("SELECT 1", [], (txn, result) => {
      console.log(2);
      throw new Error("boom");
    }, (txn, error) => {
      console.log(3, error);
      return true;
    });
  }, error => {
    console.log(4, error);
  }, () => {
    console.log(5);
  });
} catch (error) {
  console.log(6, error);
}

As per the spec of the processing model for asynchronous transactions, I would expect the following output:

1
2
4 Error: boom

And for the transaction to be rolled back. Specifically, I am referring to item 6.6 here:

If the callback was invoked and raised an exception, jump to the last step in the overall steps.

Instead, I get the following output:

1
2
/tmp/foo/dbtxn.js:11
      throw new Error("boom");
            ^

Error: boom
    at SQLTask.sqlCallback (/tmp/foo/dbtxn.js:11:13)
    at /tmp/foo/node_modules/websql/lib/websql/WebSQLTransaction.js:70:19
    at checkDone (/tmp/foo/node_modules/websql/lib/sqlite/SQLiteDatabase.js:50:7)
    at /tmp/foo/node_modules/websql/lib/sqlite/SQLiteDatabase.js:59:7
    at Statement.<anonymous> (/tmp/foo/node_modules/websql/lib/sqlite/SQLiteDatabase.js:21:5)

And the whole process terminates with an exit code of 1.