From 276ab5935873edc05e1882c06fc527a14babd27c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 30 Jan 2023 14:50:47 -0700 Subject: encoder, reencoder: Distinguish between syntax errors and I/O errors --- reencode.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'reencode.go') diff --git a/reencode.go b/reencode.go index e48c58c..d19dc1a 100644 --- a/reencode.go +++ b/reencode.go @@ -232,7 +232,7 @@ func (enc *ReEncoder) Close() error { } if len(enc.barriers) == 0 { if err := enc.handleRune(0, jsonparse.RuneTypeError, enc.stackSize()); err != nil { - enc.err = &ReEncodeSyntaxError{ + enc.err = &ReEncodeWriteError{ Err: err, Offset: enc.inputPos, } @@ -274,8 +274,14 @@ rehandle: } return enc.written, enc.err } - enc.err = enc.handleRune(c, t, enc.stackSize()) - if enc.err == nil && t == jsonparse.RuneTypeEOF { + if err := enc.handleRune(c, t, enc.stackSize()); err != nil { + enc.err = &ReEncodeWriteError{ + Err: err, + Offset: enc.inputPos, + } + return enc.written, enc.err + } + if t == jsonparse.RuneTypeEOF { if enc.AllowMultipleValues && len(enc.barriers) == 0 { enc.par.Reset() goto rehandle -- cgit v1.2.3-2-g168b