From 18e354874e1c7ec261c1edf5933849f2c2b2b564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20S=C3=B5ro?= Date: Fri, 9 Oct 2026 10:10:23 +0300 Subject: [PATCH] [compass_app] Fix Command to capture `action` exceptions as `Result`. --- compass_app/app/lib/utils/command.dart | 2 ++ compass_app/app/test/utils/command_test.dart | 11 +++++++++++ 2 files changed, 13 insertions(+) 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', () {