Repository navigation
Report exceptions thrown by aggregate and window steps - #16
Conversation
js_execute_common() turned the result of a function into an SQL result only when the caller wanted the value. The step function of an aggregate or window function, and the inverse function of a window function, return nothing, so their result was dropped, and with it any exception they threw: the aggregate went on as if the row had been added or removed. A step that threw, or ran out of memory, gave a wrong result with no error. Report an exception thrown by a step or inverse function as an SQL error. Reported from xStep or xInverse, it makes SQLite abort the statement, which still calls xFinal, so the aggregate context is released as before. Add an Aggregate errors test: an exception in an aggregate step and in a window inverse function each fail the statement with its message, and the connection stays usable. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
|
Merged into Verified locally on macOS/arm64: universal build with no new warnings, full suite green, clean under ASan + UBSan, and the final memory check still reports no leak — which is the thing I most wanted to confirm, since erroring from The new Aggregate errors test is load-bearing: with the three-line change reverted, Worth noting that this fixes a second, quieter bug as a side effect: before this, an exception from a step or inverse function was never retrieved, so Nothing needed changing. Three lines, a real bug, a test that proves it — thanks. |
The step function of an aggregate or window function, and the inverse function of a window function, return nothing, so
js_execute_common()drops their result, and with it any exception they throw. The aggregate then goes on as if the row had been added or removed: a step that throws, or runs out of memory, gives a wrong result with no error.This reports an exception thrown by a step or inverse function as an SQL error. Reported from xStep or xInverse, the error makes SQLite abort the statement; SQLite still calls xFinal, so the aggregate context is released as before.
Test: a new Aggregate errors test checks that an exception in an aggregate step, and one in a window inverse function, each fail the statement with its message, and that the connection stays usable. The final memory check still finds no leak.
make testpasses on x86_64 Linux, also under ASan and UBSan.These are six separate pull requests, #11 to #16, so each can be taken or declined on its own; only #15 depends on another (#14). They add tests at the same places in
test/main.c, and #11 and #12 both add code just aboveglobaljs_init(), so those merged later will need a small rebase, which we will do.This pull request originated with AI. Claude, Anthropic's AI model, wrote the code, the tests and this description while packaging sqlite-js for Code on the Go, App Dev For All's Android IDE, which ships sqlite-js with this change. Contact: [email protected]
🤖 Generated with Claude Code
https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw