fsm icon indicating copy to clipboard operation
fsm copied to clipboard

self transitions result in no:transition

Open UtkarshBhatthere opened this issue 1 year ago • 2 comments

okay this is frustrating. I am not sure why and how this is still unfixed even after being documented in various bugs (#19 , #98) and even in PRs (#106)

UtkarshBhatthere avatar Aug 20 '24 19:08 UtkarshBhatthere

One could say this is a feature, not a bug, so just add a function like this in your program:

func isNotTransitionError(err error) bool {
	var noTransitionError fsm.NoTransitionError
	return errors.As(err, &noTransitionError)
}

and check for if err != nil && !isNotTransitionError(err)

fgmarand avatar Jan 15 '25 17:01 fgmarand

Additional caution may be needed: NoTransitionError can also happen in other situations, in which case the NoTransitionError will wrap another error. This can be checked like that:

func isNotError(err error) bool {
	var ntErr fsm.NoTransitionError
	return err == nil || (errors.As(err, &ntErr) && ntErr.Err == nil)
}

This is arguably safer than my January version.

fgmarand avatar Aug 21 '25 09:08 fgmarand