You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 1, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Jul 1, 2026. It is now read-only.
If I try to use Promises with node-sqlite3, verbose() doesn't work.
consider the following example:
constsqlite3=require('sqlite3').verbose();constdb=newsqlite3.Database(':memory:');functiondb_run(sql){returnnewPromise((resolve,reject)=>{db.run(sql,err=>{if(err){console.log('callback has error ...');reject(err);}else{resolve()}});});}db_run('update non_existent_table set id=1').catch(err=>{console.log('promise rejected ...');throwerr;});
This works as expected and I get the promise rejected, but the error I get doesn't have any trace information :
$ node app
callback has error ...
promise rejected ...
(node:15600) UnhandledPromiseRejectionWarning: Error: SQLITE_ERROR: no such table: non_existent_table
(node:15600) 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:15600) [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.
The docs says that I should throw the error, if I throw it in Promise.catch() I don't get the trace,
But if I throw it in db_run in the callback instead of reject(err), I get the trace information but the promise never rejects because throw err happens in an async callback so the promise doesn't catch it, neither does placing a try/catch around the callback.
$ node app
callback has error ...
C:\sqlite-test\node_modules\sqlite3\lib\trace.js:36
throw err;
^
Error: SQLITE_ERROR: no such table: non_existent_table
--> in Database#run('update non_existent_table set id=1', [Function])
at C:\sqlite-test\app.js:6:8
at new Promise (<anonymous>)
at db_run (C:\sqlite-test\app.js:5:10)
at Object.<anonymous> (C:\sqlite-test\app.js:18:1)
←[90m at Module._compile (internal/modules/cjs/loader.js:955:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:811:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:723:14)←[39m
←[90m at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)←[39m {
errno: ←[33m1←[39m,
code: ←[32m'SQLITE_ERROR'←[39m,
__augmented: ←[33mtrue←[39m
Activity