spring-projects / spring-statemachine

Spring Statemachine is a framework for application developers to use state machine concepts with Spring.
1.54k stars 604 forks source link

Make exceptions that prevent transitions available #970

Open egreijus opened 3 years ago

egreijus commented 3 years ago

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)

jvalkeal commented 3 years ago

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?

egreijus commented 3 years ago

Good point. It's been refactored now.

davidjohansson commented 2 years ago

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.

tarockx commented 1 year ago

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

giovanni-mazzucco-e-projectsrl commented 1 year ago

Catching exceptions and being able to log them is crucial. For me it is a necessary change as soon as possible

Zhoth commented 1 year ago

Please accept this pull request because it's a crucial feature for my project.

Ma55imo commented 1 year ago

Please pull