-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
sqlite: custom function callback errors should be reported to sqlite API #56772
Comments
Fixes nodejs#56772 Add error reporting for custom function callback errors to the sqlite API. * **src/node_sqlite.cc** - Call `sqlite3_result_error()` in `UserDefinedFunction::xFunc` when the JS callback throws an error. - Update the `retval` check to handle the error condition and call `sqlite3_result_error()`. * **test/parallel/test-sqlite-custom-functions.js** - Add a new test to verify that custom function callback errors are reported to the sqlite API. - Write tests to ensure that error conditions in the JS callback result in `sqlite3_result_error()` being called. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/nodejs/node/issues/56772?shareId=XXXX-XXXX-XXXX-XXXX).
This commit adds support for the situation where SQLite is trying to report an error while JavaScript already has an exception pending. Fixes: nodejs#56772
Nice find. I've put together a patch in cjihrig@f113c39. There is already another PR though (#56773), so I'm not sure how we want to proceed. Even though |
My $0.02 would be that there are considerations beyond simply adding a one-liner (I was going to comment about the other silent returns, but the point about deduplicating exceptions is a very good one) that make the best course of action to open a new PR and supersede the first. With what would likely be a lot of iterations of recommend-modify-review, I doubt the existing one would be committable in time for the current release cycle. |
This commit adds support for the situation where SQLite is trying to report an error while JavaScript already has an exception pending. Fixes: nodejs#56772
This commit adds support for the situation where SQLite is trying to report an error while JavaScript already has an exception pending. Fixes: nodejs#56772
In the callback wrapper for user-provided functions (ie. those added with
DatabaseSync#function()
), error conditions in the JS callback result in an early return to the sqlite API:node/src/node_sqlite.cc
Lines 202 to 207 in 1c7c32f
In sqlite, this results in the return value of the user-defined function being implicitly set to NULL. It does not signal an error condition from the callback.
This raises the potential for user function callbacks to encounter error conditions, but still cause side-effects in sqlite. As a basic example:
Error conditions in the user function callback should call
sqlite3_result_error()
in order to signal the sqlite API that an error has occurred and that the query should be aborted.The text was updated successfully, but these errors were encountered: