-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
109 lines (102 loc) · 4.58 KB
/
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
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
101
102
103
104
105
106
107
108
109
package csv
import (
"fmt"
"github.com/nicksnyder/go-i18n/v2/i18n"
)
// Error is an error that is used to localize error messages.
type Error struct {
id string
subMessage string
localizer *i18n.Localizer
}
// Error returns the localized error message.
func (e *Error) Error() string {
if e.subMessage != "" {
return fmt.Sprintf(
"%s: %s",
e.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: e.id,
}),
e.subMessage,
)
}
return e.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: e.id,
})
}
// Is reports whether the target error is the same as the error.
func (e *Error) Is(target error) bool {
t, ok := target.(*Error)
if !ok {
return false
}
return e.id == t.id
}
// NewError returns a new Error.
func NewError(localizer *i18n.Localizer, id, subMessage string) *Error {
return &Error{
id: id,
subMessage: subMessage,
localizer: localizer,
}
}
var (
// ErrStructSlicePointerID is the error ID used when the value is not a pointer to a struct slice.
ErrStructSlicePointerID = "ErrStructSlicePointer"
// ErrInvalidOneOfFormatID is the error ID used when the target is not one of the specified values.
ErrInvalidOneOfFormatID = "ErrInvalidOneOfFormat"
// ErrInvalidThresholdFormatID is the error ID used when the threshold format is invalid.
ErrInvalidThresholdFormatID = "ErrInvalidThresholdFormat"
// ErrInvalidBooleanID is the error ID used when the target is not a boolean.
ErrInvalidBooleanID = "ErrInvalidBoolean"
// ErrInvalidAlphabetID is the error ID used when the target is not an alphabetic character.
ErrInvalidAlphabetID = "ErrInvalidAlphabet"
// ErrInvalidNumericID is the error ID used when the target is not a numeric character.
ErrInvalidNumericID = "ErrInvalidNumeric"
// ErrInvalidAlphanumericID is the error ID used when the target is not an alphanumeric character.
ErrInvalidAlphanumericID = "ErrInvalidAlphanumeric"
// ErrRequiredID is the error ID used when the target is required but is empty.
ErrRequiredID = "ErrRequired"
// ErrEqualID is the error ID used when the target is not equal to the threshold value.
ErrEqualID = "ErrEqual"
// ErrInvalidThresholdID is the error ID used when the threshold value is invalid.
ErrInvalidThresholdID = "ErrInvalidThreshold"
// ErrNotEqualID is the error ID used when the target is equal to the threshold value.
ErrNotEqualID = "ErrNotEqual"
// ErrGreaterThanID is the error ID used when the target is not greater than the threshold value.
ErrGreaterThanID = "ErrGreaterThan"
// ErrGreaterThanEqualID is the error ID used when the target is not greater than or equal to the threshold value.
ErrGreaterThanEqualID = "ErrGreaterThanEqual"
// ErrLessThanID is the error ID used when the target is not less than the threshold value.
ErrLessThanID = "ErrLessThan"
// ErrLessThanEqualID is the error ID used when the target is not less than or equal to the threshold value.
ErrLessThanEqualID = "ErrLessThanEqual"
// ErrMinID is the error ID used when the target is less than the minimum value.
ErrMinID = "ErrMin"
// ErrMaxID is the error ID used when the target is greater than the maximum value.
ErrMaxID = "ErrMax"
// ErrLengthID is the error ID used when the target length is not equal to the threshold value.
ErrLengthID = "ErrLength"
// ErrOneOfID is the error ID used when the target is not one of the specified values.
ErrOneOfID = "ErrOneOf"
// ErrInvalidStructID is the error ID used when the target is not a struct.
ErrInvalidStructID = "ErrInvalidStruct"
// ErrUnsupportedTypeID is the error ID used when the target is an unsupported type.
ErrUnsupportedTypeID = "ErrUnsupportedType"
// ErrLowercaseID is the error ID used when the target is not a lowercase character.
ErrLowercaseID = "ErrLowercase"
// ErrUppercaseID is the error ID used when the target is not an uppercase character.
ErrUppercaseID = "ErrUppercase"
// ErrASCIIID is the error ID used when the target is not an ASCII character.
ErrASCIIID = "ErrASCII"
// ErrEmailID is the error ID used when the target is not an email.
ErrEmailID = "ErrEmail"
// ErrContainsID is the error ID used when the target does not contain the specified value.
ErrContainsID = "ErrContains"
// ErrInvalidContainsFormatID is the error ID used when the contains format is invalid.
ErrInvalidContainsFormatID = "ErrInvalidContainsFormat"
// ErrContainsAnyID is the error ID used when the target does not contain any of the specified values.
ErrContainsAnyID = "ErrContainsAny"
// ErrInvalidContainsAnyFormatID is the error ID used when the contains any format is invalid.
ErrInvalidContainsAnyFormatID = "ErrInvalidContainsAnyFormat"
)