sdk-go icon indicating copy to clipboard operation
sdk-go copied to clipboard

OnError - how to tell whether Transition or End is defined (which to use)?

Open globalflea opened this issue 3 years ago • 3 comments

What is the question: Since the OnError struct defines both Transition & End as struct and not pointers, how should i check if either is "defined" since i can't check for nil?

globalflea avatar Dec 14 '21 04:12 globalflea

We can change that to a pointer instead so you can check it for nil.

ricardozanini avatar Dec 14 '21 18:12 ricardozanini

actually, i am currently check if Transition.NextState is empty string to infer that Transition is not defined, which then implies it is End. Not sure if this is the right approach.

globalflea avatar Dec 15 '21 09:12 globalflea

In spec transition/end are mutually exclusive. If both are present, its a validation error that should be caught at compile time imo.

the checks are really, if end exists, and its value is true then its ending state. If transition exists and its value is not empty, its a transition. if both exist well then you didnt validate the dsl :)

There can be an additional check for transitions at validation/compile time to make sure that the state its trying to transition to actually exists.

Also note that Switch states are unique their end/transition definitions should be in conditions / default condition. We might need to fix the schema for that for 0.9 if its not clear.

Same rules for checking transition/end also applies to onError defs

tsurdilo avatar Dec 15 '21 14:12 tsurdilo