Note: This question is specifically geared towards the Stateless library for C#, and its implementation of State Machines.
Scenario:
I have a typical State Machine. However, I need a way to recover to a different state if I get an unexpected bad trigger.
OnUnhandledTrigger
and OnUnhandledTriggerAsync
can be used to call functionality when a bad trigger has been thrown for a state. But what is the Best Practice for trying to move to an 'Error State' that can feed back into the normal state machine? After all, I cannot directly 'set' the State of the State Machine.
Should I create a Temporary Transition, force it to Fire, and then delete the Transition? Should I create in-between storage so I can force the State to be set outside of the State Machine object? Or is there a different approach to take here?
Example case
Definitions:
start --[trigger.accept]-> accepting
accepting --[trigger.subnegotiate]-> subnegotiation
subnegotiation --[trigger.1]-> echo
subnegotiation --[trigger.expectedbadtrigger]-> errorstate
States triggered
trigger.accept --> accepting
trigger.subnegotiate --> subnegotiation
trigger.unexpectedbadtrigger --> [Calls OnUnhandledTrigger]
I need the unexpectedbadtrigger
to move the state to errorstate
.