summaryrefslogtreecommitdiff
path: root/encode.go
diff options
context:
space:
mode:
Diffstat (limited to 'encode.go')
-rw-r--r--encode.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/encode.go b/encode.go
index fa337ad..00848ed 100644
--- a/encode.go
+++ b/encode.go
@@ -146,7 +146,11 @@ func encode(w io.Writer, val reflect.Value, escaper BackslashEscaper, quote bool
}})
}
if err := validator.Close(); err != nil && !errors.Is(err, iofs.ErrClosed) {
- panic(encodeError{err})
+ panic(encodeError{&EncodeMethodError{
+ Type: val.Type(),
+ SourceFunc: "EncodeJSON",
+ Err: err,
+ }})
}
case val.Kind() != reflect.Pointer && val.CanAddr() && reflect.PointerTo(val.Type()).Implements(jsonMarshalerType):
@@ -173,10 +177,18 @@ func encode(w io.Writer, val reflect.Value, escaper BackslashEscaper, quote bool
// Use a sub-ReEncoder to check that it's a full element.
validator := &ReEncoder{Out: w, BackslashEscape: escaper}
if _, err := validator.Write(dat); err != nil {
- panic(encodeError{err})
+ panic(encodeError{&EncodeMethodError{
+ Type: val.Type(),
+ SourceFunc: "MarshalJSON",
+ Err: err,
+ }})
}
if err := validator.Close(); err != nil {
- panic(encodeError{err})
+ panic(encodeError{&EncodeMethodError{
+ Type: val.Type(),
+ SourceFunc: "MarshalJSON",
+ Err: err,
+ }})
}
case val.Kind() != reflect.Pointer && val.CanAddr() && reflect.PointerTo(val.Type()).Implements(textMarshalerType):