@@ -5,6 +5,15 @@ import (
55 "reflect"
66)
77
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+
817// DecodeError is a generic error type that holds information about
918// a decoding error together with the name of the field that caused the error.
1019type DecodeError struct {
@@ -31,27 +40,35 @@ func (e *DecodeError) Error() string {
3140 return fmt .Sprintf ("'%s' %s" , e .name , e .err )
3241}
3342
43+ func (* DecodeError ) mapstructure () {}
44+
3445// ParseError is an error type that indicates a value could not be parsed
3546// into the expected type.
3647type ParseError struct {
3748 Expected reflect.Value
38- Value interface {}
49+ Value any
3950 Err error
4051}
4152
4253func (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 )
4555}
4656
57+ func (* ParseError ) mapstructure () {}
58+
4759// UnconvertibleTypeError is an error type that indicates a value could not be
4860// converted to the expected type.
4961type UnconvertibleTypeError struct {
5062 Expected reflect.Value
51- Value interface {}
63+ Value any
5264}
5365
5466func (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+ )
5772}
73+
74+ func (* UnconvertibleTypeError ) mapstructure () {}
0 commit comments