Browse Source

reflection: introduce UnmarshalTypeError{}

Signed-off-by: Alejandro Mery <amery@jpi.io>
dev-amery-reflect
Alejandro Mery 1 year ago
parent
commit
f68272eb84
  1. 25
      reflection/error.go

25
reflection/error.go

@ -42,3 +42,28 @@ func (e *InvalidUnmarshalError) Error() string {
return buf.String()
}
// An UnmarshalTypeError tells something went wrong while processing
// a type.
type UnmarshalTypeError struct {
Prefix string
Err error
reflect.Type
}
func (e UnmarshalTypeError) Unwrap() error {
return e.Err
}
func (e UnmarshalTypeError) Error() string {
var buf bytes.Buffer
if e.Prefix != "" {
_, _ = fmt.Fprintf(&buf, "%s: ", e.Prefix)
}
_, _ = fmt.Fprintf(&buf, "%s: %s", e.Type.String(), e.Err)
return buf.String()
}

Loading…
Cancel
Save