Skip to content

Report errors that converting values and storing functions used to drop - #36

Merged
marcobambini merged 3 commits into
sqliteai:mainfrom
davidschachterADFA:check-ignored-errors
Nov 21, 2026
Merged

marcobambini merged 3 commits into
sqliteai:mainfrom
davidschachterADFA:check-ignored-errors

Conversation

@davidschachterADFA

Copy link
Copy Markdown
Contributor

Three results in sqlitejs.c were dropped. The test program also left one of its own checks out of its exit code. A code review of Code on the Go's Android library, which vendors 1.4.3, found all four.

1. Building the arguments of a call, or the rows of toArray() (js_execute_common, js_rowset_to_array)

Putting a value into the array can fail, either because QuickJS runs out of memory or because a script has put a setter on Array.prototype. Before this change, the function then ran with fewer arguments, toArray() returned shorter rows, and the exception stayed pending.

Now the call fails with that exception, before the function runs or another row is read. JS_SetPropertyUint32 frees the value it is given, also when it fails, so the error paths free only the arrays. As when toArray() fails to allocate a row today, the result set stays open after the row that failed. A script that catches the exception and reads on gets the rows after it.

2. Text that SQLite cannot convert (sqlite_value_to_js)

sqlite3_value_text() returns NULL when SQLite runs out of memory converting text to UTF-8, for example on a UTF-16 database. JS_NewString() passed that NULL to strlen(), which crashed. It is now an "out of memory" error.

3. A function that cannot be stored (js_create_function)

When js_add_to_table() could not store a function in js_functions, for example on a read-only connection, js_create_*() still reported success. The function then worked on that connection but was gone when the database was reopened.

Now it is an error with SQLite's code. The message says the function was registered on this connection but could not be stored, and gives SQLite's reason.

This changes behaviour. js_create_*() on a read-only connection whose database has js_functions used to report success. It now reports this error, although the function still works on that connection. A database without js_functions behaves as before.

4. The test program's exit code

main() printed the result of its final "Memory" check but did not add it to the value it returns, so a leak alone still exited 0.

Tests. Two new tests fail without these changes:

  • Conversion errors covers a throwing Array.prototype[0] setter, for both arguments and toArray(). It also binds 1M characters of UTF-16 with too little heap left (sqlite3_hard_heap_limit64) for their UTF-8 copy. That case passes only when the statement fails with SQLITE_NOMEM. Without fix 2, it crashed in strlen.
  • Store errors covers js_create_scalar() on a read-only connection.

The suite passes 19 of 19 on Linux x86_64, also as an embedded build under ASan, LeakSanitizer and UBSan.

This pull request originates with AI: it was written by Claude (Anthropic's model) for App Dev For All. The human contact is David Schachter, davidschachter@appdevforall.org.

davidschachterADFA and others added 3 commits November 17, 2026 13:35
Three results were ignored:

- Putting a value into the array of a call's arguments, or of a row of
  toArray(), can fail: QuickJS runs out of memory, or a script has put a
  setter on Array.prototype. The function then ran with fewer arguments,
  and toArray() returned shorter rows, with the exception left pending.
  Now the call fails with that exception, before the function runs or
  another row is read.
- sqlite3_value_text() returns NULL when SQLite runs out of memory
  converting text to UTF-8, and JS_NewString() passed it to strlen(),
  which crashed. Now it is an "out of memory" error.
- js_create_*() reported success when js_functions could not store the
  function (on a read-only connection, for example), so it was gone when
  the database was reopened. Now it is an error that says the function
  was registered on this connection but not stored, with SQLite's code.

The new tests "Conversion errors" and "Store errors" fail without these
changes; the text conversion case crashed.

This change originates with AI: it was written by Claude (Anthropic's
model) for App Dev For All. Contact: davidschachter@appdevforall.org.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
main() printed the result of its final "Memory" check (memory still in
use after every test) but left it out of the value it returns, so a leak
alone let the run exit 0 and pass CI.

This change originates with AI: it was written by Claude (Anthropic's
model) for App Dev For All. Contact: davidschachter@appdevforall.org.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
- The text conversion case now passes only when the statement fails with
  SQLITE_NOMEM, so a failure for any other reason cannot pass it without
  reaching the conversion.
- The UTF-16 path for sqlite3_open16() is spelled as an array, since a
  u"" literal needs C11.

This change originates with AI: it was written by Claude (Anthropic's
model) for App Dev For All. Contact: davidschachter@appdevforall.org.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
@davidschachterADFA

Copy link
Copy Markdown
Contributor Author

A gentle ping when you have a moment. Code on the Go now carries these three fixes as a local patch on 1.4.3, and will drop it as soon as a release includes them. Happy to rebase or change anything you'd like.

Posted by Claude, an AI assistant, on behalf of David Schachter.

@marcobambini
marcobambini merged commit c09ec7c into sqliteai:main Nov 21, 2026
15 checks passed
@marcobambini

Copy link
Copy Markdown
Member

Thank you for this pull request and for the careful write-up! All four fixes are merged and shipped in 1.4.4. The new tests did their job: without the fixes they fail, and without the UTF-8 conversion check the UTF-16 test crashes in strlen. The change to js_create_*() is noted in the changelog under Changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants