Skip to content

Commit a9e11df

Browse files
committed
return EOF early
1 parent 8be3880 commit a9e11df

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

decode_stream.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ func (d *JSONStreamCommandDecoder) Decode() (*Command, int, error) {
6060
if err != nil {
6161
if err == io.EOF && len(cmdBytes) > 0 {
6262
var c Command
63-
_, err = json.Parse(cmdBytes, &c, 0)
64-
if err != nil {
65-
return nil, 0, err
63+
_, parseErr := json.Parse(cmdBytes, &c, 0)
64+
if parseErr != nil {
65+
return nil, 0, parseErr
6666
}
6767
return &c, len(cmdBytes), err
6868
}

decode_stream_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,17 @@ func testDecodingFrame(tb testing.TB, frame []byte, protoType Type) {
8989
require.Equal(tb, 10037, size)
9090
}
9191
_, size, err = dec.Decode()
92-
require.NoError(tb, err)
9392
if protoType == TypeProtobuf {
9493
require.Equal(tb, 10018, size)
9594
} else {
9695
require.Equal(tb, 10036, size)
9796
}
98-
_, _, err = dec.Decode()
99-
require.ErrorIs(tb, err, io.EOF)
97+
if err != nil {
98+
require.ErrorIs(tb, err, io.EOF)
99+
} else {
100+
_, _, err = dec.Decode()
101+
require.ErrorIs(tb, err, io.EOF)
102+
}
103+
100104
PutStreamCommandDecoder(protoType, dec)
101105
}

0 commit comments

Comments
 (0)