diff --git a/compatible_shim.go b/compatible_shim.go index 8999d53..7d75662 100644 --- a/compatible_shim.go +++ b/compatible_shim.go @@ -84,7 +84,7 @@ func (e *Error) MarshalJSON() ([]byte, error) { // and the original global registry is removed. // This function is reserved for compatibility. func (e *Error) UnmarshalJSON(data []byte) error { - tErr := &jsonError{} + var tErr jsonError if err := json.Unmarshal(data, &tErr); err != nil { return Trace(err) } diff --git a/compatible_shim_test.go b/compatible_shim_test.go index 1ba9ed8..c576095 100644 --- a/compatible_shim_test.go +++ b/compatible_shim_test.go @@ -33,6 +33,12 @@ func TestUnmarshalJSONClearsLocalState(t *testing.T) { require.Equal(t, message, decoded.Msg) } +func TestUnmarshalJSONNullClearsError(t *testing.T) { + e := Error{code: 123, codeText: "executor:123", message: "old message"} + require.NoError(t, json.Unmarshal([]byte(`null`), &e)) + require.Equal(t, Error{}, e) +} + func TestUnmarshalJSONInvalidInputPreservesError(t *testing.T) { for _, input := range []string{ `{"message":"new message",`,