-
Notifications
You must be signed in to change notification settings - Fork 8
/
error.go
71 lines (65 loc) · 1.34 KB
/
error.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package flag
import "fmt"
type (
errorType uint8
flagError struct {
Type errorType
Value string
}
)
const (
errNonPointer errorType = iota + 1
errFlagNotFound
errInvalidNames
errInvalidType
errInvalidValue
errDuplicateFlagRegister
errFlagValueNotProvided
errNonFlagValue
errDuplicateFlagParsed
errInvalidSelects
errInvalidDefault
errInvalidStructure
errPositionalFlagNotProvided
)
func (t errorType) String() string {
switch t {
case 0:
return "NoError"
case errNonPointer:
return "NonPointerStructure "
case errFlagNotFound:
return "FlagNotFound"
case errInvalidNames:
return "InvalidNames"
case errInvalidType:
return "InvalidType"
case errInvalidValue:
return "InvalidValue"
case errDuplicateFlagRegister:
return "DuplicateFlagRegister"
case errFlagValueNotProvided:
return "FlagValueNotProvided"
case errNonFlagValue:
return "NonFlagValue"
case errDuplicateFlagParsed:
return "DuplicateFlagParsed"
case errInvalidSelects:
return "InvalidSelects"
case errInvalidStructure:
return "InvalidStructure"
case errPositionalFlagNotProvided:
return "PositionalFlagNotProvided"
default:
return "UnknownError"
}
}
func (e flagError) Error() string {
return e.Value
}
func newErrorf(t errorType, format string, v ...interface{}) error {
return flagError{
Type: t,
Value: fmt.Sprintf(format, v...),
}
}