Skip to content

Commit 59827ac

Browse files
trivikraduh95
authored andcommitted
sqlite: isolate applyChangeset filter errors
Track filter callback failures within each applyChangeset() invocation. Returning false from xFilter is not a SQLite error. This previously left the database-wide suppression flag set, which could hide the next unrelated SQLite error. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: codex:gpt-5.6-sol PR-URL: #64823 Fixes: #64822 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent 5a01df2 commit 59827ac

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎src/node_sqlite.cc‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,7 @@ void DatabaseSync::ApplyChangeset(const FunctionCallbackInfo<Value>& args) {
23392339

23402340
Local<Function> conflictFunc;
23412341
Local<Function> filterFunc;
2342+
bool filterCallbackFailed = false;
23422343
if (args.Length() > 1 && !args[1]->IsUndefined()) {
23432344
if (!args[1]->IsObject()) {
23442345
THROW_ERR_INVALID_ARG_TYPE(env->isolate(),
@@ -2400,25 +2401,25 @@ void DatabaseSync::ApplyChangeset(const FunctionCallbackInfo<Value>& args) {
24002401

24012402
filterFunc = filterValue.As<Function>();
24022403

2403-
context.filterCallback =
2404-
[env, db, &filterFunc](std::string_view item) -> bool {
2404+
context.filterCallback = [env, &filterFunc, &filterCallbackFailed](
2405+
std::string_view item) -> bool {
24052406
// If there was an error in the previous call to the filter's
24062407
// callback, we skip calling it again.
2407-
if (db->ignore_next_sqlite_error_) {
2408+
if (filterCallbackFailed) {
24082409
return false;
24092410
}
24102411

24112412
Local<Value> argv[1];
24122413
if (!ToV8Value(env->context(), item, env->isolate())
24132414
.ToLocal(&argv[0])) {
2414-
db->SetIgnoreNextSQLiteError(true);
2415+
filterCallbackFailed = true;
24152416
return false;
24162417
}
24172418

24182419
Local<Value> result;
24192420
if (!filterFunc->Call(env->context(), Null(env->isolate()), 1, argv)
24202421
.ToLocal(&result)) {
2421-
db->SetIgnoreNextSQLiteError(true);
2422+
filterCallbackFailed = true;
24222423
return false;
24232424
}
24242425

‎test/parallel/test-sqlite-session.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,13 @@ test('filter handler throws', (t) => {
404404
name: 'Error',
405405
message: 'Error filtering table data1'
406406
});
407+
408+
t.assert.throws(() => {
409+
database2.exec('CREATE TABLEEEE');
410+
}, {
411+
code: 'ERR_SQLITE_ERROR',
412+
message: /syntax error/,
413+
});
407414
});
408415

409416
test('database.createSession() - filter changes', (t) => {

0 commit comments

Comments
 (0)