fsm
fsm copied to clipboard
self transitions result in no:transition
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)
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)
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.