-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
64 lines (52 loc) · 1.07 KB
/
errors.go
File metadata and controls
64 lines (52 loc) · 1.07 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 cfg
import (
"fmt"
"reflect"
"github.com/upfluence/cfg/provider"
)
type RequiredError struct {
Field reflect.StructField
}
func (re *RequiredError) Error() string {
return fmt.Sprintf(
"required field %s.%s has no value",
re.Field.Type.Name(),
re.Field.Name,
)
}
type ProvidingError struct {
Err error
Key string
Field reflect.StructField
Provider provider.Provider
}
func (pe *ProvidingError) Unwrap() error { return pe.Err }
func (pe *ProvidingError) Error() string {
return fmt.Sprintf(
"cant provide value for %s.%s(%q, %q): %s",
pe.Field.Type.Name(),
pe.Field.Name,
pe.Key,
pe.Provider.StructTag(),
pe.Err.Error(),
)
}
type SettingError struct {
Err error
Value string
Key string
Field reflect.StructField
Provider provider.Provider
}
func (se *SettingError) Unwrap() error { return se.Err }
func (se *SettingError) Error() string {
return fmt.Sprintf(
"cant set value for %s.%s(%q, %q, %q): %s",
se.Field.Type.Name(),
se.Field.Name,
se.Key,
se.Provider.StructTag(),
se.Value,
se.Err.Error(),
)
}