sqlite: improve error for excess bound parameters - #65167
Closed
bitpshr wants to merge 1 commit into
Closed
Conversation
Passing more values than a prepared statement has parameters surfaced SQLite's own "column index out of range" error. That wording describes a binding index, but reads to a JavaScript caller as a problem with the table's columns rather than with the call, and it is inconsistent with the adjacent failure: binding a value of the wrong type already throws a Node-authored ERR_INVALID_ARG_VALUE from the same function. Detect the overflow before handing the index to sqlite3_bind_*() and throw an error that names the actual problem. The check runs after the scan for the next anonymous slot, so it also covers excess anonymous values passed alongside named parameters. This changes the error thrown for an existing case, so it needs semver-major treatment. Fixes: nodejs#65163 Signed-off-by: Paul Bouchon <mail@bitpshr.net>
Collaborator
|
Review requested:
|
Contributor
Author
|
Closing in favor of #65164, which does the same thing and also covers the docs. I had this in flight while building and missed that it was already open, sorry for the noise. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #65163. Passing more values than a prepared statement has parameters surfaced SQLite's own
column index out of rangeerror, which reads as a problem with the table's columns rather than with the call, and is inconsistent with the adjacent failure (a wrong-type value already throws a Node-authored error from the same function).This detects the overflow before handing the index to
sqlite3_bind_*(). The check sits after the scan for the next anonymous slot, so it also covers excess anonymous values passed alongside named parameters.Three notes for reviewers, since I deviated from the issue's suggestions:
test-sqlite-statement-sync.jshad a test asserting the oldERR_SQLITE_ERROR/errcode: 25, so the change is a deliberate behavior change. That test is updated here and renamed, since the error no longer comes from SQLite.ERR_INVALID_ARG_COUNTdoes not exist innode_errors.horlib/internal/errors.js, so I usedERR_INVALID_ARG_VALUE. It is already aTypeErrorand is what the sibling binding failure a few lines away uses, which keeps the two consistent.run({ $k: 1 }, 2)would have read "accepts 1, but 1 were provided". The current wording is accurate in every case.Verified locally against a build: the full sqlite suite passes (18/18), and correct arity still binds normally. Happy to change the error code, the wording, or drop this entirely if you'd rather leave the behavior alone.
Fixes: #65163