We encountered a bug today where an e instanceof Error check failed on a better-sqlite3 SqliteError instance because the instance came from a different realm. (This was within our Jest test suite; Jest uses Node.js's vm API to execute each test module in a different realm. As I understand it, better-sqlite3's native module was loaded within one realm then reused in the second, causing two different instances of the global Error class to be active.)
JavaScript now offers an Error.isError function to help with this, but it doesn't work on SqliteError: it uses a private class field to check whether the provided value is an instance of a subclass of Error. However, SqliteError isn't a "real" subclass of Error; it instead uses ES5-style prototype manipulation to act like a subclass of Error.
Could SqliteError be updated to be compatible with Error.isError?
class SqliteError extends Error {
constructor(message, code) {
super(message);
// ...
}
}
I can open a PR if you like. Since better-sqlite3's package.json declares that it requires Node.js 20 or above, I don't think it would be a problem to use ES6 classes, but I wanted to check.
Thank you.
We encountered a bug today where an
e instanceof Errorcheck failed on a better-sqlite3SqliteErrorinstance because the instance came from a different realm. (This was within our Jest test suite; Jest uses Node.js's vm API to execute each test module in a different realm. As I understand it, better-sqlite3's native module was loaded within one realm then reused in the second, causing two different instances of the globalErrorclass to be active.)JavaScript now offers an
Error.isErrorfunction to help with this, but it doesn't work on SqliteError: it uses a private class field to check whether the provided value is an instance of a subclass ofError. However, SqliteError isn't a "real" subclass of Error; it instead uses ES5-style prototype manipulation to act like a subclass of Error.Could SqliteError be updated to be compatible with
Error.isError?I can open a PR if you like. Since better-sqlite3's package.json declares that it requires Node.js 20 or above, I don't think it would be a problem to use ES6 classes, but I wanted to check.
Thank you.