diff options
Diffstat (limited to 'compat/json')
-rw-r--r-- | compat/json/compat.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/compat/json/compat.go b/compat/json/compat.go index 8d6ec35..59eff6c 100644 --- a/compat/json/compat.go +++ b/compat/json/compat.go @@ -78,6 +78,9 @@ func convertReEncodeError(err error) error { msg: se.Err.Error(), Offset: se.Offset + 1, } + if errors.Is(se.Err, io.ErrUnexpectedEOF) { + err.(*SyntaxError).msg = "unexpected end of JSON input" + } } return err } @@ -91,6 +94,9 @@ func HTMLEscape(dst *bytes.Buffer, src []byte) { func reencode(src []byte, formatter *lowmemjson.ReEncoder) error { _, err := formatter.Write(src) + if err == nil { + err = formatter.Close() + } return convertReEncodeError(err) } @@ -130,6 +136,9 @@ func convertDecodeError(err error) error { msg: terr.Err.Error(), Offset: terr.Offset, } + if errors.Is(terr.Err, io.ErrUnexpectedEOF) { + err.(*SyntaxError).msg = "unexpected end of JSON input" + } case *lowmemjson.DecodeTypeError: if typeErr, ok := terr.Err.(*json.UnmarshalTypeError); ok { err = &UnmarshalTypeError{ @@ -160,7 +169,7 @@ func convertDecodeError(err error) error { } func Unmarshal(data []byte, ptr any) error { - return convertDecodeError(lowmemjson.Decode(bytes.NewReader(data), ptr)) + return convertDecodeError(lowmemjson.DecodeThenEOF(bytes.NewReader(data), ptr)) } type Decoder struct { |