@@ -5,6 +5,17 @@ import (
5
5
"reflect"
6
6
)
7
7
8
+ // Error interface is implemented by all errors emitted by mapstructure.
9
+ //
10
+ // Errors from underlying libraries MAY not be wrapped.
11
+ //
12
+ // Use [errors.As] to check if an error implements this interface.
13
+ type Error interface {
14
+ error
15
+
16
+ mapstructure ()
17
+ }
18
+
8
19
// DecodeError is a generic error type that holds information about
9
20
// a decoding error together with the name of the field that caused the error.
10
21
type DecodeError struct {
@@ -28,30 +39,39 @@ func (e *DecodeError) Unwrap() error {
28
39
}
29
40
30
41
func (e * DecodeError ) Error () string {
31
- return fmt .Sprintf ("'%s' %s" , e .name , e .err )
42
+ return fmt .Sprintf ("decoding '%s': %s" , e .name , e .err )
32
43
}
33
44
45
+ func (* DecodeError ) mapstructure () {}
46
+
34
47
// ParseError is an error type that indicates a value could not be parsed
35
48
// into the expected type.
36
49
type ParseError struct {
37
50
Expected reflect.Value
38
- Value interface {}
51
+ Value any
39
52
Err error
40
53
}
41
54
42
55
func (e * ParseError ) Error () string {
43
- return fmt .Sprintf ("cannot parse '%s' as '%s': %s" ,
44
- e .Value , e .Expected .Type (), e .Err )
56
+ return fmt .Sprintf ("cannot parse '%s' as '%s': %s" , e .Value , e .Expected .Type (), e .Err )
45
57
}
46
58
59
+ func (* ParseError ) mapstructure () {}
60
+
47
61
// UnconvertibleTypeError is an error type that indicates a value could not be
48
62
// converted to the expected type.
49
63
type UnconvertibleTypeError struct {
50
64
Expected reflect.Value
51
- Value interface {}
65
+ Value any
52
66
}
53
67
54
68
func (e * UnconvertibleTypeError ) Error () string {
55
- return fmt .Sprintf ("expected type '%s', got unconvertible type '%s', value: '%v'" ,
56
- e .Expected .Type (), reflect .TypeOf (e .Value ), e .Value )
69
+ return fmt .Sprintf (
70
+ "expected type '%s', got unconvertible type '%s', value: '%v'" ,
71
+ e .Expected .Type (),
72
+ reflect .TypeOf (e .Value ),
73
+ e .Value ,
74
+ )
57
75
}
76
+
77
+ func (* UnconvertibleTypeError ) mapstructure () {}
0 commit comments