Skip to content

Commit

Permalink
add introspection interfaces for some fsm errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Vorontsov committed Jul 29, 2024
1 parent b2f0ab5 commit 9ad9b6c
Showing 1 changed file with 28 additions and 0 deletions.
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

0 comments on commit 9ad9b6c

Please sign in to comment.