From 7e0b7cfb47616fdfb34d795101e3ffff1188c053 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Sat, 2 Sep 2023 04:04:12 +0000 Subject: [PATCH] reflective: introduce UnmarshalTypeError{} Signed-off-by: Alejandro Mery --- reflective/error.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/reflective/error.go b/reflective/error.go index b8c085a..d9aac1d 100644 --- a/reflective/error.go +++ b/reflective/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() +}