diff options
author | Luke Shumaker <lukeshu@datawire.io> | 2022-08-15 22:29:52 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@datawire.io> | 2022-08-16 00:05:39 -0600 |
commit | 83ec1924ae051b60f911aa8b53b741c5371faaf8 (patch) | |
tree | f014234317559fe0d5c64a2df79d1a12efae6e38 /compat/json/borrowed_misc.go | |
parent | 67b78f25f76b8ca43d837fb8055ca8e2b06c7d02 (diff) |
Get borrowed_encode_test.go passing [ci-skip]
Diffstat (limited to 'compat/json/borrowed_misc.go')
-rw-r--r-- | compat/json/borrowed_misc.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/compat/json/borrowed_misc.go b/compat/json/borrowed_misc.go index 30a3b0e..e6b0162 100644 --- a/compat/json/borrowed_misc.go +++ b/compat/json/borrowed_misc.go @@ -4,6 +4,10 @@ package json +import ( + "reflect" +) + // A SyntaxError is a description of a JSON syntax error. // Unmarshal will return a SyntaxError if the JSON can't be parsed. type SyntaxError struct { @@ -12,3 +16,23 @@ type SyntaxError struct { } func (e *SyntaxError) Error() string { return e.msg } + +// A MarshalerError represents an error from calling a MarshalJSON or MarshalText method. +type MarshalerError struct { + Type reflect.Type + Err error + sourceFunc string +} + +func (e *MarshalerError) Error() string { + srcFunc := e.sourceFunc + if srcFunc == "" { + srcFunc = "MarshalJSON" + } + return "json: error calling " + srcFunc + + " for type " + e.Type.String() + + ": " + e.Err.Error() +} + +// Unwrap returns the underlying error. +func (e *MarshalerError) Unwrap() error { return e.Err } |