summaryrefslogtreecommitdiff
path: root/encode.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-30 14:50:47 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-02-10 21:55:49 -0700
commit276ab5935873edc05e1882c06fc527a14babd27c (patch)
treeba9ec20307b4200f1010bc291d78c3786b57e326 /encode.go
parentc604347f1950e3dfbef2f524da8a63692848da27 (diff)
encoder, reencoder: Distinguish between syntax errors and I/O errors
Diffstat (limited to 'encode.go')
-rw-r--r--encode.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/encode.go b/encode.go
index b6541cd..d39c862 100644
--- a/encode.go
+++ b/encode.go
@@ -83,6 +83,12 @@ func (enc *Encoder) Encode(obj any) (err error) {
enc.w.par.Reset()
}
if err := encode(enc.w, reflect.ValueOf(obj), enc.w.BackslashEscape, false, 0, map[any]struct{}{}); err != nil {
+ if rwe, ok := err.(*ReEncodeWriteError); ok {
+ err = &EncodeWriteError{
+ Err: rwe.Err,
+ Offset: rwe.Offset,
+ }
+ }
return err
}
if enc.isRoot {