spring-statemachine icon indicating copy to clipboard operation
spring-statemachine copied to clipboard

Make exceptions that prevent transitions available

Open egreijus opened this issue 3 years ago • 7 comments

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:

  1. An invalid state transition. The source state of the machine does not match any of the valid transitions configured.
  2. Insufficient (or unauthenticated) access rights. The state transition requires a role the user does not have.
  3. 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)

egreijus avatar Jun 22 '21 14:06 egreijus

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?

jvalkeal avatar Jun 26 '21 15:06 jvalkeal

Good point. It's been refactored now.

egreijus avatar Jun 27 '21 12:06 egreijus

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.

davidjohansson avatar Dec 14 '21 12:12 davidjohansson

Was this ever addressed? I'm facing the same issue, is this PR currently the best solution?

tarockx avatar Feb 01 '23 18:02 tarockx

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.

Zhoth avatar Feb 17 '23 09:02 Zhoth

Please pull

Ma55imo avatar Feb 17 '23 09:02 Ma55imo