From 20c4c655102bfab832dd43dc4233a7a40d966ce2 Mon Sep 17 00:00:00 2001 From: Brian Shih Date: Mon, 22 Apr 2024 11:08:18 -0400 Subject: [PATCH] read ErrUnexpectedEOF --- decoder_test.go | 6 +++--- reader.go | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/decoder_test.go b/decoder_test.go index bda9d27d..ac59d95b 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -68,7 +68,7 @@ func TestDecoder_DecodeNilPtr(t *testing.T) { assert.Error(t, err) } -func TestDecoder_DecodeEOFDoesntReturnError(t *testing.T) { +func TestDecoder_DecodeEOF(t *testing.T) { defer ConfigTeardown() data := []byte{0xE2} @@ -78,7 +78,7 @@ func TestDecoder_DecodeEOFDoesntReturnError(t *testing.T) { var i int err := dec.Decode(&i) - assert.NoError(t, err) + assert.Error(t, err) } func TestUnmarshal(t *testing.T) { @@ -87,7 +87,7 @@ func TestUnmarshal(t *testing.T) { schema := avro.MustParse("int") var i int - err := avro.Unmarshal(schema, []byte{0xE2}, &i) + err := avro.Unmarshal(schema, []byte{0x13}, &i) assert.NoError(t, err) } diff --git a/reader.go b/reader.go index 5d39e89d..edc1e793 100644 --- a/reader.go +++ b/reader.go @@ -117,6 +117,7 @@ func (r *Reader) Read(b []byte) { for read < size { if r.head == r.tail { if !r.loadMore() { + r.Error = io.ErrUnexpectedEOF return } } @@ -174,6 +175,7 @@ func (r *Reader) ReadInt() int32 { // We ran out of buffer and are not at the end of the int, // Read more into the buffer. if !r.loadMore() { + r.Error = io.ErrUnexpectedEOF return 0 } } @@ -216,6 +218,7 @@ func (r *Reader) ReadLong() int64 { // We ran out of buffer and are not at the end of the long, // Read more into the buffer. if !r.loadMore() { + r.Error = io.ErrUnexpectedEOF return 0 } } @@ -247,9 +250,6 @@ func (r *Reader) ReadBytes() []byte { // ReadString reads a String from the Reader. func (r *Reader) ReadString() string { b := r.readBytes("string") - if r.Error != nil { - r.Error = fmt.Errorf("reading string: %w", r.Error) - } if len(b) == 0 { return "" @@ -288,6 +288,7 @@ func (r *Reader) readBytes(op string) []byte { } buf := make([]byte, size) + r.Read(buf) return buf }