-
Notifications
You must be signed in to change notification settings - Fork 2
/
errors.go
70 lines (56 loc) · 1.47 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
package config
import (
"errors"
"fmt"
"strings"
)
var (
ErrInvalidMaskTag = errors.New("invalid mask tag")
)
// LoadError is an error returned when a config fails to load. It contains Errors, a slice of
// any errors that occurred during config load.
type LoadError struct {
// Errors that were found while loading a config.
Errors []error
}
func newLoadError(errs []error) *LoadError {
return &LoadError{Errors: errs}
}
func (le *LoadError) Error() string {
var errs []string
for _, errStr := range le.Errors {
errs = append(errs, errStr.Error())
}
return "failed to load config: " + strings.Join(errs, ", ")
}
// SerializeError is an error returned when a config loader fails to serialize a field
// in a config struct.
type SerializeError struct {
FieldName string
Err error
}
func newSerializeError(fieldName string, serializeErr error) *SerializeError {
return &SerializeError{
FieldName: fieldName,
Err: serializeErr,
}
}
func (se *SerializeError) Error() string {
return fmt.Sprintf("field '%s': %s", se.FieldName, se.Err)
}
func (se *SerializeError) Unwrap() error {
return se.Err
}
// PostLoadError is an error returned when a config's PostLoad method fails.
type PostLoadError struct {
Err error
}
func newPostLoadError(err error) *PostLoadError {
return &PostLoadError{Err: err}
}
func (ple *PostLoadError) Error() string {
return "post load callback failed: " + ple.Err.Error()
}
func (ple *PostLoadError) Unwrap() error {
return ple.Err
}