-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.go
More file actions
100 lines (81 loc) · 2.04 KB
/
errors.go
File metadata and controls
100 lines (81 loc) · 2.04 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package figtree
import (
"fmt"
)
// ErrorFor returns an error on a given name if one exists
func (tree *figTree) ErrorFor(name string) error {
tree.mu.RLock()
defer tree.mu.RUnlock()
name = tree.resolveName(name)
fruit, exists := tree.figs[name]
if !exists || fruit == nil {
return fmt.Errorf("no tree named %s", name)
}
return fruit.Error
}
func (fig *figFruit) Unwrap() error {
return fig.Error
}
type ErrInvalidType struct {
Wanted Mutagenesis
Got any
}
func (e ErrInvalidType) Error() string {
return fmt.Sprintf("invalid type ; got %s ; wanted %s", e.Got, e.Wanted.Kind())
}
type ErrConversion struct {
From Mutagenesis
To Mutagenesis
Got any
}
func (e ErrConversion) Error() string {
return fmt.Sprintf("failed to convert %v (type %T) type %s into %s", e.Got, e.Got, e.From.Kind(), e.To.Kind())
}
type ErrInvalidValue struct {
Name string
Err error
}
func (e ErrInvalidValue) Error() string {
return fmt.Sprintf("invalid value for flag -%s: %s", e.Name, e.Err.Error())
}
func (e ErrInvalidValue) Unwrap() error {
return e.Err
}
const (
ErrWayBeBelow string = "be below"
ErrWayBeAbove string = "be above"
ErrWayBeBetweenFmt string = "be between %v and %v"
ErrWayBePositive string = "be positive"
ErrWayBeNegative string = "be negative"
ErrWayBeNotNaN string = "not be NaN"
)
type ErrValue struct {
Way string
Value any
Than any
}
func (e ErrValue) Error() string {
if e.Than != nil {
return fmt.Sprintf("invalid value ; must be %s than %v ; got %v", e.Way, e.Value, e.Than)
}
return fmt.Sprintf("invalid value ; must be %s ; got %v", e.Way, e.Value)
}
type ErrLoadFailure struct {
What string
Err error
}
func (e ErrLoadFailure) Error() string {
return fmt.Sprintf("failed to load %s: %s", e.What, e.Err.Error())
}
func (e ErrLoadFailure) Unwrap() error {
return e.Err
}
type ErrValidationFailure struct {
Err error
}
func (e ErrValidationFailure) Error() string {
return fmt.Sprintf("failed to validateAll with err: %v", e.Err)
}
func (e ErrValidationFailure) Unwrap() error {
return e.Err
}