Skip to content

Commit 33750be

Browse files
committed
Test serialized exceptions
1 parent 9b4b3df commit 33750be

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

packages/sqlite_async/lib/src/web/database.dart

+6-1
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,14 @@ Future<T> wrapSqliteException<T>(Future<T> Function() callback) async {
311311
try {
312312
return await callback();
313313
} on RemoteException catch (ex) {
314+
if (ex.exception case final serializedCause?) {
315+
throw serializedCause;
316+
}
317+
318+
// Older versions of package:sqlite_web reported SqliteExceptions as strings
319+
// only.
314320
if (ex.toString().contains('SqliteException')) {
315321
RegExp regExp = RegExp(r'SqliteException\((\d+)\)');
316-
// The SQLite Web package wraps these in remote errors
317322
throw SqliteException(
318323
int.parse(regExp.firstMatch(ex.message)?.group(1) ?? '0'),
319324
ex.message);

packages/sqlite_async/pubspec.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ dev_dependencies:
3232
path: ^1.9.0
3333
test_descriptor: ^2.0.2
3434

35-
dependency_overrides:
36-
sqlite3_web:
37-
path: /Users/simon/src/sqlite3.dart/sqlite3_web
38-
3935
platforms:
4036
android:
4137
ios:

packages/sqlite_async/test/basic_test.dart

+13
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ void main() {
175175
? 'Fails due to compiler bug, https://dartbug.com/59981'
176176
: null,
177177
);
178+
179+
test('reports exceptions as SqliteExceptions', () async {
180+
final db = await testUtils.setupDatabase(path: path);
181+
await expectLater(
182+
db.get('SELECT invalid_statement;'),
183+
throwsA(
184+
isA<SqliteException>()
185+
.having((e) => e.causingStatement, 'causingStatement',
186+
'SELECT invalid_statement;')
187+
.having((e) => e.extendedResultCode, 'extendedResultCode', 1),
188+
),
189+
);
190+
});
178191
});
179192
}
180193

0 commit comments

Comments
 (0)