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