Skip to content

There is no way to catch an error while in a transaction #21

Closed
@alextekartik

Description

@alextekartik

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions