From a9e11df2c5fccf8c3f0397fea0321ac09555265c Mon Sep 17 00:00:00 2001 From: FZambia Date: Sat, 30 Mar 2024 10:51:50 +0200 Subject: [PATCH] return EOF early --- decode_stream.go | 6 +++--- decode_stream_test.go | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/decode_stream.go b/decode_stream.go index bd38d79..43a1d37 100644 --- a/decode_stream.go +++ b/decode_stream.go @@ -60,9 +60,9 @@ func (d *JSONStreamCommandDecoder) Decode() (*Command, int, error) { if err != nil { if err == io.EOF && len(cmdBytes) > 0 { var c Command - _, err = json.Parse(cmdBytes, &c, 0) - if err != nil { - return nil, 0, err + _, parseErr := json.Parse(cmdBytes, &c, 0) + if parseErr != nil { + return nil, 0, parseErr } return &c, len(cmdBytes), err } diff --git a/decode_stream_test.go b/decode_stream_test.go index 4bc35d9..5e86606 100644 --- a/decode_stream_test.go +++ b/decode_stream_test.go @@ -89,13 +89,17 @@ func testDecodingFrame(tb testing.TB, frame []byte, protoType Type) { require.Equal(tb, 10037, size) } _, size, err = dec.Decode() - require.NoError(tb, err) if protoType == TypeProtobuf { require.Equal(tb, 10018, size) } else { require.Equal(tb, 10036, size) } - _, _, err = dec.Decode() - require.ErrorIs(tb, err, io.EOF) + if err != nil { + require.ErrorIs(tb, err, io.EOF) + } else { + _, _, err = dec.Decode() + require.ErrorIs(tb, err, io.EOF) + } + PutStreamCommandDecoder(protoType, dec) }