diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-30 14:50:47 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-10 21:55:49 -0700 |
commit | 276ab5935873edc05e1882c06fc527a14babd27c (patch) | |
tree | ba9ec20307b4200f1010bc291d78c3786b57e326 /errors.go | |
parent | c604347f1950e3dfbef2f524da8a63692848da27 (diff) |
encoder, reencoder: Distinguish between syntax errors and I/O errors
Diffstat (limited to 'errors.go')
-rw-r--r-- | errors.go | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -121,6 +121,18 @@ func (e *DecodeError) Unwrap() error { return e.Err } // encode errors /////////////////////////////////////////////////////////////////////////////////// +// A EncodeWriteError is returned from Encode if there is an error +// writing to the output stream. +type EncodeWriteError struct { + Err error + Offset int64 +} + +func (e *EncodeWriteError) Error() string { + return fmt.Sprintf("json: I/O error at output byte %v: %v", e.Offset, e.Err) +} +func (e *EncodeWriteError) Unwrap() error { return e.Err } + // An EncodeTypeError is returned by Encode when attempting to encode // an unsupported type. // @@ -155,6 +167,18 @@ func (e *EncodeMethodError) Unwrap() error { return e.Err } // reencode errors ///////////////////////////////////////////////////////////////////////////////// +// A ReEncodeWriteError is returned from ReEncoder's methods if there +// is an error writing to the output stream. +type ReEncodeWriteError struct { + Err error + Offset int64 +} + +func (e *ReEncodeWriteError) Error() string { + return fmt.Sprintf("json: I/O error at output byte %v: %v", e.Offset, e.Err) +} +func (e *ReEncodeWriteError) Unwrap() error { return e.Err } + // A ReEncodeSyntaxError is returned from ReEncoder's methods if there // is a syntax error in the input. type ReEncodeSyntaxError struct { |