Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func (e NoTransitionError) Error() string {
return "no transition"
}

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 +86,10 @@ func (e CanceledError) Error() string {
return "transition canceled"
}

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 +106,10 @@ func (e AsyncError) Error() string {
return "async started"
}

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
18 changes: 18 additions & 0 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ func TestNoTransitionError(t *testing.T) {
if e.Error() != "no transition with error: "+e.Err.Error() {
t.Error("NoTransitionError string mismatch")
}
if e.Unwrap() == nil {
t.Error("CanceledError Unwrap() should not be nil")
}
if !errors.Is(e, e.Err) {
t.Error("CanceledError should be equal to its error")
}
}

func TestCanceledError(t *testing.T) {
Expand All @@ -71,6 +77,12 @@ func TestCanceledError(t *testing.T) {
if e.Error() != "transition canceled with error: "+e.Err.Error() {
t.Error("CanceledError string mismatch")
}
if e.Unwrap() == nil {
t.Error("CanceledError Unwrap() should not be nil")
}
if !errors.Is(e, e.Err) {
t.Error("CanceledError should be equal to its error")
}
}

func TestAsyncError(t *testing.T) {
Expand All @@ -82,6 +94,12 @@ func TestAsyncError(t *testing.T) {
if e.Error() != "async started with error: "+e.Err.Error() {
t.Error("AsyncError string mismatch")
}
if e.Unwrap() == nil {
t.Error("AsyncError Unwrap() should not be nil")
}
if !errors.Is(e, e.Err) {
t.Error("AsyncError should be equal to its error")
}
}

func TestInternalError(t *testing.T) {
Expand Down