-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors.go
More file actions
64 lines (50 loc) · 1.84 KB
/
errors.go
File metadata and controls
64 lines (50 loc) · 1.84 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
package settings
import "errors"
var (
ErrTheModelHasEmptyStruct = errors.New("an input struct has no fields")
ErrNotAStruct = errors.New("the configuration must be a struct")
ErrNotAddressable = errors.New("the main struct must be pointed out via pointer")
ErrNotAddressableField = errors.New("the value is not addressable or main struct is not indicated via pointer")
ErrInternalFailure = errors.New("an internal package error")
)
type unsupportedFieldError string
func (err unsupportedFieldError) Error() string {
return "environment variable '" + string(err) + "' has been found but the field type is unsupported"
}
func (err unsupportedFieldError) Is(target error) bool {
_, ok := target.(unsupportedFieldError)
return ok
}
type incorrectFieldValueError string
func (err incorrectFieldValueError) Error() string {
return "environment variable '" + string(err) + "' has been found but has incorrect value"
}
func (err incorrectFieldValueError) Is(target error) bool {
_, ok := target.(incorrectFieldValueError)
return ok
}
type validationFailedError struct {
Name string
Type string
ValidationRule string
}
func (err *validationFailedError) Error() string {
return "validation with rule '" + err.ValidationRule + "' failed on the field '" + err.Name + "' of '" + err.Type + "' type"
}
func (err *validationFailedError) Is(target error) bool {
_, ok := target.(*validationFailedError)
return ok
}
func NewUnsupportedFieldError(fieldName string) error {
return unsupportedFieldError(fieldName)
}
func NewIncorrectFieldValueError(fieldName string) error {
return incorrectFieldValueError(fieldName)
}
func NewValidationFailedError(name, fieldType, validationRule string) error {
return &validationFailedError{
Name: name,
Type: fieldType,
ValidationRule: validationRule,
}
}