-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
48 lines (39 loc) · 958 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package flowstate
type ErrCommitConflict struct {
cmds []string
stateIDs []StateID
errs []error
}
func (err ErrCommitConflict) As(target interface{}) bool {
if targetErr, ok := target.(*ErrCommitConflict); ok {
*targetErr = err
return true
}
return false
}
func (err ErrCommitConflict) Error() string {
msg := "conflict;"
for i := range err.cmds {
msg += " cmd: " + err.cmds[i] + " sid: " + string(err.stateIDs[i]) + ";"
if err.errs[i] != nil {
msg += " err: " + err.errs[i].Error() + ";"
}
}
return msg
}
func (err *ErrCommitConflict) Add(cmd string, sID StateID, cmdErr error) {
err.cmds = append(err.cmds, cmd)
err.stateIDs = append(err.stateIDs, sID)
err.errs = append(err.errs, cmdErr)
}
func (err *ErrCommitConflict) TaskIDs() []StateID {
return err.stateIDs
}
func (err *ErrCommitConflict) Contains(sID StateID) bool {
for _, s := range err.stateIDs {
if s == sID {
return true
}
}
return false
}