File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ func (e NoTransitionError) Error() string {
6969 return "no transition"
7070}
7171
72+ func (e NoTransitionError ) Unwrap () error {
73+ return e .Err
74+ }
75+
7276// CanceledError is returned by FSM.Event() when a callback have canceled a
7377// transition.
7478type CanceledError struct {
@@ -82,6 +86,10 @@ func (e CanceledError) Error() string {
8286 return "transition canceled"
8387}
8488
89+ func (e CanceledError ) Unwrap () error {
90+ return e .Err
91+ }
92+
8593// AsyncError is returned by FSM.Event() when a callback have initiated an
8694// asynchronous state transition.
8795type AsyncError struct {
@@ -98,6 +106,10 @@ func (e AsyncError) Error() string {
98106 return "async started"
99107}
100108
109+ func (e AsyncError ) Unwrap () error {
110+ return e .Err
111+ }
112+
101113// InternalError is returned by FSM.Event() and should never occur. It is a
102114// probably because of a bug.
103115type InternalError struct {}
Original file line number Diff line number Diff line change @@ -60,6 +60,12 @@ func TestNoTransitionError(t *testing.T) {
6060 if e .Error () != "no transition with error: " + e .Err .Error () {
6161 t .Error ("NoTransitionError string mismatch" )
6262 }
63+ if e .Unwrap () == nil {
64+ t .Error ("CanceledError Unwrap() should not be nil" )
65+ }
66+ if ! errors .Is (e , e .Err ) {
67+ t .Error ("CanceledError should be equal to its error" )
68+ }
6369}
6470
6571func TestCanceledError (t * testing.T ) {
@@ -71,6 +77,12 @@ func TestCanceledError(t *testing.T) {
7177 if e .Error () != "transition canceled with error: " + e .Err .Error () {
7278 t .Error ("CanceledError string mismatch" )
7379 }
80+ if e .Unwrap () == nil {
81+ t .Error ("CanceledError Unwrap() should not be nil" )
82+ }
83+ if ! errors .Is (e , e .Err ) {
84+ t .Error ("CanceledError should be equal to its error" )
85+ }
7486}
7587
7688func TestAsyncError (t * testing.T ) {
@@ -82,6 +94,12 @@ func TestAsyncError(t *testing.T) {
8294 if e .Error () != "async started with error: " + e .Err .Error () {
8395 t .Error ("AsyncError string mismatch" )
8496 }
97+ if e .Unwrap () == nil {
98+ t .Error ("AsyncError Unwrap() should not be nil" )
99+ }
100+ if ! errors .Is (e , e .Err ) {
101+ t .Error ("AsyncError should be equal to its error" )
102+ }
85103}
86104
87105func TestInternalError (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments