spring-statemachine
spring-statemachine copied to clipboard
Make exceptions that prevent transitions available
Sometimes it's desirable to know what caused the denial of a state transition. For instance, a user might want to trigger a state transition by submitting an event coupled with data. In this case the transition might fail because of:
- An invalid state transition. The source state of the machine does not match any of the valid transitions configured.
- Insufficient (or unauthenticated) access rights. The state transition requires a role the user does not have.
- Exception thrown by an action that is run for the state transition.
In each of these cases the user can be made aware of the outcome (transition/no transition) but it's quite complicated to find out the reason to why a transition would be denied. Getting hold of the exception that prevented the transition would make this a lot easier.
This problem has been mentioned in issues: https://github.com/spring-projects/spring-statemachine/issues/548, https://github.com/spring-projects/spring-statemachine/issues/553 and https://github.com/spring-projects/spring-statemachine/issues/340 and this proposed change provides a way to get hold of this piece of information.
(A CLA has been completed)
I think we should expose error in a different way as setting it on a machine itself is wrong. You would never really know from where that throwable was set and it'd stay there forever. Maybe we could enhance StateMachineEventResult
or something around it to expose what you need?
Good point. It's been refactored now.
Any progress on this issue? We are facing the same problem and need to find a way to get the exception that was thrown inside of an action.
Was this ever addressed? I'm facing the same issue, is this PR currently the best solution?
Catching exceptions and being able to log them is crucial. For me it is a necessary change as soon as possible
Please accept this pull request because it's a crucial feature for my project.
Please pull