Improve error handling in LazyDatabase

This commit is contained in:
Simon Binder 2021-12-01 21:22:53 +01:00
parent ab20d69846
commit 6dc198ecca
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 10 additions and 2 deletions

View File

@ -29,11 +29,11 @@ class LazyDatabase extends QueryExecutor {
return _openDelegate!.future; return _openDelegate!.future;
} else { } else {
final delegate = _openDelegate = Completer(); final delegate = _openDelegate = Completer();
Future.value(opener()).then((database) { Future.sync(opener).then((database) {
_delegate = database; _delegate = database;
_delegateAvailable = true; _delegateAvailable = true;
delegate.complete(); delegate.complete();
}); }, onError: delegate.completeError);
return delegate.future; return delegate.future;
} }
} }

View File

@ -95,4 +95,12 @@ void main() {
verify(inner.close()); verify(inner.close());
}); });
test('throws when opening method throws', () {
final exception = Exception('expected');
final lazy = LazyDatabase(() => throw exception);
final user = _LazyQueryUserForTest();
expect(lazy.ensureOpen(user), throwsA(exception));
});
} }