-
Notifications
You must be signed in to change notification settings - Fork 95
Description
I was never able to make verbose
work with this library, consider the following example :
const sqlite3 = require('sqlite3');
const { open } = require('sqlite');
sqlite3.verbose();
(async () => {
const db = await open({
filename: ':memory:',
driver: sqlite3.Database
});
db.run('select * from non_existent_table').catch(err => {
console.log('promise rejected ...')
throw err;
});
})()
It's a very basic example, but the error throws doesn't have any trace info :
$ node app
promise rejected ...
(node:14036) UnhandledPromiseRejectionWarning: Error: SQLITE_ERROR: no such table: non_existent_table
(node:14036) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14036) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I first thought it was a bug, I forked the repo and tried to solve it, but it turned out it's not possible from this library because node-sqlite3
adds the trace info by catching an error you should throw, and throwing it instead of reject()
causes the promise to never reject because an error thrown in an async callback cannot be caught by the promise.
I then sent an issue and a PR to fix it in node-sqlite3
repo.
I opened this issue here for anyone trying to figure out why it's not working with node-sqlite
, please keep it open until the problem is fixed in the other repo, if it's not accepted there then update the docs so no one loses his mind trying to figure out the problem.