blob: 9c32a498da48e6f92f4f69eb847201ac5837a60c [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001// Copyright (c) 2013 - Max Persson <max@looplab.se>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package fsm
16
17// InvalidEventError is returned by FSM.Event() when the event cannot be called
18// in the current state.
19type InvalidEventError struct {
20 Event string
21 State string
22}
23
24func (e InvalidEventError) Error() string {
25 return "event " + e.Event + " inappropriate in current state " + e.State
26}
27
28// UnknownEventError is returned by FSM.Event() when the event is not defined.
29type UnknownEventError struct {
30 Event string
31}
32
33func (e UnknownEventError) Error() string {
34 return "event " + e.Event + " does not exist"
35}
36
37// InTransitionError is returned by FSM.Event() when an asynchronous transition
38// is already in progress.
39type InTransitionError struct {
40 Event string
41}
42
43func (e InTransitionError) Error() string {
44 return "event " + e.Event + " inappropriate because previous transition did not complete"
45}
46
47// NotInTransitionError is returned by FSM.Transition() when an asynchronous
48// transition is not in progress.
49type NotInTransitionError struct{}
50
51func (e NotInTransitionError) Error() string {
52 return "transition inappropriate because no state change in progress"
53}
54
55// NoTransitionError is returned by FSM.Event() when no transition have happened,
56// for example if the source and destination states are the same.
57type NoTransitionError struct {
58 Err error
59}
60
61func (e NoTransitionError) Error() string {
62 if e.Err != nil {
63 return "no transition with error: " + e.Err.Error()
64 }
65 return "no transition"
66}
67
68// CanceledError is returned by FSM.Event() when a callback have canceled a
69// transition.
70type CanceledError struct {
71 Err error
72}
73
74func (e CanceledError) Error() string {
75 if e.Err != nil {
76 return "transition canceled with error: " + e.Err.Error()
77 }
78 return "transition canceled"
79}
80
81// AsyncError is returned by FSM.Event() when a callback have initiated an
82// asynchronous state transition.
83type AsyncError struct {
84 Err error
85}
86
87func (e AsyncError) Error() string {
88 if e.Err != nil {
89 return "async started with error: " + e.Err.Error()
90 }
91 return "async started"
92}
93
94// InternalError is returned by FSM.Event() and should never occur. It is a
95// probably because of a bug.
96type InternalError struct{}
97
98func (e InternalError) Error() string {
99 return "internal error on state transition"
100}