diff --git a/compass_app/app/lib/utils/command.dart b/compass_app/app/lib/utils/command.dart index 1df59621612..8dfba87da42 100644 --- a/compass_app/app/lib/utils/command.dart +++ b/compass_app/app/lib/utils/command.dart @@ -63,6 +63,8 @@ abstract class Command extends ChangeNotifier { try { _result = await action(); + } on Exception catch (e) { + _result = Result.error(e); } finally { _running = false; notifyListeners(); diff --git a/compass_app/app/test/utils/command_test.dart b/compass_app/app/test/utils/command_test.dart index 733f383f3ff..9dfad63f611 100644 --- a/compass_app/app/test/utils/command_test.dart +++ b/compass_app/app/test/utils/command_test.dart @@ -75,6 +75,17 @@ void main() { expect(command.error, true); expect(command.result, isA()); }); + + test('should handle action exceptions', () async { + final command = Command0( + () => 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()); + }); }); group('Command1 tests', () {