From 6efe11327ddadf5da16502e8afe4e8822693de8c Mon Sep 17 00:00:00 2001 From: kennytm Date: Fri, 27 Nov 2026 01:58:42 +0800 Subject: [PATCH] compatible_shim: avoid unnecessary double indirection in UnmarshalJSON() --- compatible_shim.go | 2 +- compatible_shim_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compatible_shim.go b/compatible_shim.go index 8999d530..7d75662f 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 1ba9ed8d..c576095f 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",`,