summaryrefslogtreecommitdiff
path: root/errors.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 /errors.go
parentc604347f1950e3dfbef2f524da8a63692848da27 (diff)
encoder, reencoder: Distinguish between syntax errors and I/O errors
Diffstat (limited to 'errors.go')
-rw-r--r--errors.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/errors.go b/errors.go
index 0a47db4..516018c 100644
--- a/errors.go
+++ b/errors.go
@@ -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 {