-
-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SqliteErrors are silently swallowed inside Worker Threads #575
Comments
The worker demo from the docs shows the same behavior and prints a generic object
|
I originally thought this happened because |
This can also be reproduced by simply doing If we cannot make Personally I will now handle |
I can't call this a bug with |
I agree about 51%. But Would you be opposed to a PR that adds an option to only throw native |
The reason for Can't you just write a try-catch block around your worker code, detect |
I see
I would like to keep the simplicity of the Edit: Also if I wanted to make a custom error logic using |
This worked for me: master.jsconst { Worker } = require('worker_threads');
const worker = new Worker('./worker.js');
worker
.on('online', () => {
console.log('online');
})
.on('error', (err) => {
console.log('error: %s', err);
})
.on('exit', (code) => {
console.log('exit: %s', code);
process.exit();
}); worker.jsconst { SqliteError } = require('better-sqlite3');
function propagateThreadError(err) {
if (err instanceof SqliteError) {
const nativeErr = new Error(err.message);
nativeErr.isSqliteError = true;
nativeErr.code = err.code;
nativeErr.stack = err.stack;
err = nativeErr;
}
throw err;
}
process.on('uncaughtException', propagateThreadError);
process.on('unhandledRejection', propagateThreadError);
// These wrapper functions are just to demonstrate that the stack trace is preserved.
(function foo() {
(function bar() {
throw new SqliteError('oops!', 'FAKE_CODE');
})();
})(); |
OMG I found the problem. And maybe it's a bug in Node.js. The code you've posted is basically identical to what I've tried and it didn't work. I just tracked this down and the exit code is 0. Similar to your worker example I only look at So I guess we can consider this solved. I might enhance your code by using |
Node v14.16.0
better-sqlite3 7.1.1
index.js
worker.js
Steps
node index.js
{}
which is easy to miss in logsThrowing a regular error results in this:
The text was updated successfully, but these errors were encountered: