Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add introspection interfaces for some fsm errors #108

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package fsm

import (
"context"
"errors"
)

// InvalidEventError is returned by FSM.Event() when the event cannot be called
Expand Down Expand Up @@ -69,6 +70,15 @@ func (e NoTransitionError) Error() string {
return "no transition"
}

func (e NoTransitionError) Is(target error) bool {
_, ok := target.(NoTransitionError)
return ok || errors.Is(e.Err, target)
}

func (e NoTransitionError) Unwrap() error {
return e.Err
}

// CanceledError is returned by FSM.Event() when a callback have canceled a
// transition.
type CanceledError struct {
Expand All @@ -82,6 +92,15 @@ func (e CanceledError) Error() string {
return "transition canceled"
}

func (e CanceledError) Is(target error) bool {
_, ok := target.(CanceledError)
return ok || errors.Is(e.Err, target)
}

func (e CanceledError) Unwrap() error {
return e.Err
}

// AsyncError is returned by FSM.Event() when a callback have initiated an
// asynchronous state transition.
type AsyncError struct {
Expand All @@ -98,6 +117,15 @@ func (e AsyncError) Error() string {
return "async started"
}

func (e AsyncError) Is(target error) bool {
_, ok := target.(AsyncError)
return ok || errors.Is(e.Err, target)
}

func (e AsyncError) Unwrap() error {
return e.Err
}

// InternalError is returned by FSM.Event() and should never occur. It is a
// probably because of a bug.
type InternalError struct{}
Expand Down
Loading