-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(core)!: Chain stack traces for state machines
Errors originating within state machines lose context when thrown since there is an asynchronous gap between adding an event to a state machine and when it eventually gets processed. For example, consider the following exception thrown from a state machine: ``` ERROR | MyStateMachine | Emitted error: Exception #0 MyStateMachine.doWork (file:///Users/nydillon/dev/amplify-dart/packages/amplify_core/test/state_machine/my_state_machine.dart:82:7) <asynchronous suspension> #1 MyStateMachine.resolve (file:///Users/nydillon/dev/amplify-dart/packages/amplify_core/test/state_machine/my_state_machine.dart:100:9) <asynchronous suspension> #2 StateMachine._listenForEvents (package:amplify_core/src/state_machine/state_machine.dart:237:9) <asynchronous suspension> ``` The trace ends at `listenForEvents` in the state machine, which is where the event was popped off the internal queue. But what happened before? With chaining, we get the following which provides the whole picture: ``` ERROR | MyStateMachine | Emitted error: Exception test/state_machine/my_state_machine.dart 82:7 MyStateMachine.doWork test/state_machine/my_state_machine.dart 100:9 MyStateMachine.resolve package:amplify_core/src/state_machine/state_machine.dart 238:9 StateMachine._listenForEvents ===== asynchronous gap =========================== package:amplify_core/src/state_machine/event.dart 41:47 new EventCompleter package:amplify_core/src/state_machine/state_machine.dart 127:23 StateMachineManager.accept test/state_machine/state_machine_test.dart 47:30 main.<fn>.<fn> package:test_api/src/backend/declarer.dart 215:19 Declarer.test.<fn>.<fn> package:test_api/src/backend/declarer.dart 213:7 Declarer.test.<fn> package:test_api/src/backend/invoker.dart 258:9 Invoker._waitForOutstandingCallbacks.<fn> ``` Now we can see that the exception originated due to an event which was created by calling `StateMachineManager.accept` within a test. Much better!
- Loading branch information
Dillon Nys
committed
Feb 23, 2023
1 parent
48ce72b
commit 4003deb
Showing
7 changed files
with
148 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters