-
Notifications
You must be signed in to change notification settings - Fork 2
/
errors.go
95 lines (74 loc) · 2.01 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
package envi
import (
"fmt"
"strings"
)
// InvalidKindError is returned when a field is not of the expected kind.
type InvalidKindError struct {
FieldName string
Expected string
Got string
}
func (e *InvalidKindError) Error() string {
return fmt.Sprintf("expected field %s to be kind %s got %s", e.FieldName, e.Expected, e.Got)
}
// UnmarshalError is returned when an error occurs while unmarshalling.
type UnmarshalError struct {
Type string
Err error
}
func (e *UnmarshalError) Error() string {
return fmt.Sprintf("could not unmarshal %s: %s", e.Type, e.Err.Error())
}
// ValidationError is returned when one or multiple errors occured while validating the config.
type ValidationError struct {
Errors []error
}
func (e *ValidationError) Error() string {
sb := strings.Builder{}
for _, err := range e.Errors {
sb.WriteString(err.Error())
sb.WriteString("\n")
}
return sb.String()
}
// FieldRequiredError is returned when a required field is not set.
type FieldRequiredError struct {
FieldName string
}
func (e *FieldRequiredError) Error() string {
return fmt.Sprintf("field %s is required", e.FieldName)
}
// MissingTagError is returned when a required tag is not set.
type MissingTagError struct {
Tag string
}
func (e *MissingTagError) Error() string {
return fmt.Sprintf("tag %s not set", e.Tag)
}
type InvalidTagError struct {
Tag string
}
func (e *InvalidTagError) Error() string {
return fmt.Sprintf("invalid tag %s", e.Tag)
}
// ParsingError is returned when an error occurs while parsing a value into a specific datatype.
type ParsingError struct {
Type string
Err error
}
func (e *ParsingError) Error() string {
return fmt.Sprintf("could not parse %s: %s", e.Type, e.Err.Error())
}
// CloseError is returned when one or multiple errors occured while closing the file watchers.
type CloseError struct {
Errors []error
}
func (e *CloseError) Error() string {
sb := strings.Builder{}
for _, err := range e.Errors {
sb.WriteString(err.Error())
sb.WriteString("\n")
}
return sb.String()
}