Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compass_app/app/lib/utils/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ abstract class Command<T> extends ChangeNotifier {

try {
_result = await action();
} on Exception catch (e) {
_result = Result<T>.error(e);
} finally {
_running = false;
notifyListeners();
Expand Down
11 changes: 11 additions & 0 deletions compass_app/app/test/utils/command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ void main() {
expect(command.error, true);
expect(command.result, isA<Error>());
});

test('should handle action exceptions', () async {
final command = Command0<int>(
() => Future.delayed(Duration(milliseconds: 64), () {
throw Exception('Action exceptions are captured also as Result');
}),
);
await command.execute();
expect(command.error, true);
expect(command.result, isA<Error>());
});
});

group('Command1 tests', () {
Expand Down
Loading