Skip to content

Commit 1490d09

Browse files
committed
sqlite: improve session filter error handling
1 parent 4f71c07 commit 1490d09

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/node_sqlite.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,12 @@ void DatabaseSync::ApplyChangeset(const FunctionCallbackInfo<Value>& args) {
17641764
Local<Function> filterFunc = filterValue.As<Function>();
17651765

17661766
context.filterCallback = [&](std::string_view item) -> bool {
1767+
// If there was an error in the previous call to the filter's
1768+
// callback, we skip calling it again.
1769+
if (db->ignore_next_sqlite_error_) {
1770+
return false;
1771+
}
1772+
17671773
Local<Value> argv[1];
17681774
if (!ToV8Value(env->context(), item, env->isolate())
17691775
.ToLocal(&argv[0])) {

test/parallel/test-sqlite-session.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,13 @@ test('filter handler throws', (t) => {
380380

381381
t.assert.throws(() => {
382382
database2.applyChangeset(session.changeset(), {
383-
filter: () => {
384-
throw new Error('some error');
383+
filter: (tableName) => {
384+
throw new Error(`Error filtering table ${tableName}`);
385385
}
386386
});
387387
}, {
388388
name: 'Error',
389-
message: 'some error'
389+
message: 'Error filtering table data1'
390390
});
391391
});
392392

0 commit comments

Comments
 (0)