diff --git a/pkg/container/bytejson/bytejosn_modifier_test.go b/pkg/container/bytejson/bytejosn_modifier_test.go index e1c3e71161390..f65b33f4c7f21 100644 --- a/pkg/container/bytejson/bytejosn_modifier_test.go +++ b/pkg/container/bytejson/bytejosn_modifier_test.go @@ -243,3 +243,33 @@ func TestAppendBinaryString(t *testing.T) { }) } } + +func Test_appendBinaryValElem(t *testing.T) { + tests := []struct { + name string + input any + wantType TpCode + wantErr bool + }{ + { + name: "invalid type", + input: struct{}{}, + wantType: 0, + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + gotBuf, err := appendBinaryValElem(make([]byte, 0), 0, 0, tt.input) + + if tt.wantErr { + require.Error(t, err) + return + } + + require.NoError(t, err) + require.NotEmpty(t, gotBuf) + }) + } +} diff --git a/pkg/container/bytejson/utils.go b/pkg/container/bytejson/utils.go index f9f2a1aa162bf..542901c4f5cfb 100644 --- a/pkg/container/bytejson/utils.go +++ b/pkg/container/bytejson/utils.go @@ -29,7 +29,6 @@ import ( "github.com/matrixorigin/matrixone/pkg/common/moerr" "github.com/matrixorigin/matrixone/pkg/common/util" - "github.com/pingcap/errors" ) func ParseFromString(s string) (ret ByteJson, err error) { @@ -673,7 +672,7 @@ func appendBinaryValElem(buf []byte, docOff, valEntryOff int, val any) ([]byte, elemDocOff := len(buf) typeCode, buf, err = appendBinaryJSON(buf, val) if err != nil { - return nil, errors.Trace(err) + return nil, moerr.NewInvalidArgNoCtx("invalid json value", val) } if typeCode == TpCodeLiteral { litCode := buf[elemDocOff]