Closed
Description
I tried the following unit test (Added in basic_test.dart for a quick setup):
test('Catch error in transaction', () async {
final db = await setupDatabase(path: path);
await createTables(db);
// Ok can catch here
try {
await db.getOptional('SELECT description FROM dummy1');
} catch (_) {}
await db.readTransaction((tx) async {
// Not ok, cannot catch the error here
try {
await tx.getOptional('SELECT description FROM dummy2');
} catch (_) {}
await tx.getOptional('SELECT description FROM test_data');
});
}, solo: true);
Even though I do catch the exception, the test fails.
It seems that once an error occurred there is no way to continue the transaction if we catch the exception. I guess this is by design but I think it prevents developers to catch error dynamically (such as a constraint error) while in a transaction to perform a different action in the same transaction.
Metadata
Metadata
Assignees
Labels
No labels