• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

looplab / fsm / 10146410757

29 Jul 2024 02:37PM UTC coverage: 88.478% (-4.2%) from 92.711%
10146410757

Pull #108

github

web-flow
Merge 9ad9b6cb1 into b2f0ab5cc
Pull Request #108: add introspection interfaces for some fsm errors

0 of 21 new or added lines in 1 file covered. (0.0%)

407 of 460 relevant lines covered (88.48%)

13.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.82
/errors.go
1
// 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

15
package fsm
16

17
import (
18
        "context"
19
        "errors"
20
)
21

22
// InvalidEventError is returned by FSM.Event() when the event cannot be called
23
// in the current state.
24
type InvalidEventError struct {
25
        Event string
26
        State string
27
}
28

29
func (e InvalidEventError) Error() string {
2✔
30
        return "event " + e.Event + " inappropriate in current state " + e.State
2✔
31
}
2✔
32

33
// UnknownEventError is returned by FSM.Event() when the event is not defined.
34
type UnknownEventError struct {
35
        Event string
36
}
37

38
func (e UnknownEventError) Error() string {
1✔
39
        return "event " + e.Event + " does not exist"
1✔
40
}
1✔
41

42
// InTransitionError is returned by FSM.Event() when an asynchronous transition
43
// is already in progress.
44
type InTransitionError struct {
45
        Event string
46
}
47

48
func (e InTransitionError) Error() string {
1✔
49
        return "event " + e.Event + " inappropriate because previous transition did not complete"
1✔
50
}
1✔
51

52
// NotInTransitionError is returned by FSM.Transition() when an asynchronous
53
// transition is not in progress.
54
type NotInTransitionError struct{}
55

56
func (e NotInTransitionError) Error() string {
1✔
57
        return "transition inappropriate because no state change in progress"
1✔
58
}
1✔
59

60
// NoTransitionError is returned by FSM.Event() when no transition have happened,
61
// for example if the source and destination states are the same.
62
type NoTransitionError struct {
63
        Err error
64
}
65

66
func (e NoTransitionError) Error() string {
2✔
67
        if e.Err != nil {
3✔
68
                return "no transition with error: " + e.Err.Error()
1✔
69
        }
1✔
70
        return "no transition"
1✔
71
}
72

NEW
73
func (e NoTransitionError) Is(target error) bool {
×
NEW
74
        _, ok := target.(NoTransitionError)
×
NEW
75
        return ok || errors.Is(e.Err, target)
×
NEW
76
}
×
77

NEW
78
func (e NoTransitionError) Unwrap() error {
×
NEW
79
        return e.Err
×
NEW
80
}
×
81

82
// CanceledError is returned by FSM.Event() when a callback have canceled a
83
// transition.
84
type CanceledError struct {
85
        Err error
86
}
87

88
func (e CanceledError) Error() string {
2✔
89
        if e.Err != nil {
3✔
90
                return "transition canceled with error: " + e.Err.Error()
1✔
91
        }
1✔
92
        return "transition canceled"
1✔
93
}
94

NEW
95
func (e CanceledError) Is(target error) bool {
×
NEW
96
        _, ok := target.(CanceledError)
×
NEW
97
        return ok || errors.Is(e.Err, target)
×
NEW
98
}
×
99

NEW
100
func (e CanceledError) Unwrap() error {
×
NEW
101
        return e.Err
×
NEW
102
}
×
103

104
// AsyncError is returned by FSM.Event() when a callback have initiated an
105
// asynchronous state transition.
106
type AsyncError struct {
107
        Err error
108

109
        Ctx              context.Context
110
        CancelTransition func()
111
}
112

113
func (e AsyncError) Error() string {
2✔
114
        if e.Err != nil {
3✔
115
                return "async started with error: " + e.Err.Error()
1✔
116
        }
1✔
117
        return "async started"
1✔
118
}
119

NEW
120
func (e AsyncError) Is(target error) bool {
×
NEW
121
        _, ok := target.(AsyncError)
×
NEW
122
        return ok || errors.Is(e.Err, target)
×
NEW
123
}
×
124

NEW
125
func (e AsyncError) Unwrap() error {
×
NEW
126
        return e.Err
×
NEW
127
}
×
128

129
// InternalError is returned by FSM.Event() and should never occur. It is a
130
// probably because of a bug.
131
type InternalError struct{}
132

133
func (e InternalError) Error() string {
1✔
134
        return "internal error on state transition"
1✔
135
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc