Skip to content

sqlite: improve error for excess bound parameters - #65167

Closed
bitpshr wants to merge 1 commit into
nodejs:mainfrom
bitpshr:sqlite/excess-bind-params
Closed

sqlite: improve error for excess bound parameters#65167
bitpshr wants to merge 1 commit into
nodejs:mainfrom
bitpshr:sqlite/excess-bind-params

Conversation

@bitpshr

@bitpshr bitpshr commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #65163. Passing more values than a prepared statement has parameters surfaced SQLite's own column index out of range error, 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.

before: ERR_SQLITE_ERROR       column index out of range
after:  ERR_INVALID_ARG_VALUE  Too many parameter values were provided. The statement accepts 1 parameter(s), which are already bound.

Three notes for reviewers, since I deviated from the issue's suggestions:

  • This needs semver-major treatment. test-sqlite-statement-sync.js had a test asserting the old ERR_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_COUNT does not exist in node_errors.h or lib/internal/errors.js, so I used ERR_INVALID_ARG_VALUE. It is already a TypeError and is what the sibling binding failure a few lines away uses, which keeps the two consistent.
  • The message reports only the parameter count. I first included a "but N were provided" count as suggested, but when named and anonymous parameters are mixed that number counts only the anonymous values, so 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

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>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/sqlite

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem. labels Aug 9, 2026
@bitpshr

bitpshr commented Aug 9, 2026

Copy link
Copy Markdown
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.

@bitpshr bitpshr closed this Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite: excess bound parameters produce an opaque "column index out of range" error

2 participants