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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Howdy @s6o.

I'm not sure this is actually desired... The consumer of this class might want to catch the error, and this would prevent that.

It's been a long time since I've looked at the full app code, so I'm open to being wrong here.

} 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