diff --git a/bson/value_reader.go b/bson/value_reader.go index afdd9f1d68..678c47b106 100644 --- a/bson/value_reader.go +++ b/bson/value_reader.go @@ -255,9 +255,7 @@ func (vr *valueReader) appendNextElement(dst []byte) ([]byte, error) { buf := make([]byte, length) _, err = io.ReadFull(vr.r, buf) - if errors.Is(err, io.ErrUnexpectedEOF) { - return nil, io.EOF - } else if err != nil { + if err != nil { return nil, err } dst = append(dst, buf...) @@ -682,7 +680,7 @@ func (vr *valueReader) ReadElement() (string, ValueReader, error) { return "", nil, vr.invalidDocumentLengthError() } - _ = vr.pop() + _ = vr.pop() // Ignore the error because the call here never reads from the underlying reader. return "", nil, ErrEOD } @@ -712,7 +710,7 @@ func (vr *valueReader) ReadValue() (ValueReader, error) { return nil, vr.invalidDocumentLengthError() } - _ = vr.pop() + _ = vr.pop() // Ignore the error because the call here never reads from the underlying reader. return nil, ErrEOA } @@ -726,9 +724,7 @@ func (vr *valueReader) ReadValue() (ValueReader, error) { func (vr *valueReader) read(p []byte) error { n, err := io.ReadFull(vr.r, p) - if errors.Is(err, io.ErrUnexpectedEOF) { - return io.EOF - } else if err != nil { + if err != nil { return err } vr.offset += int64(n) diff --git a/bson/value_reader_test.go b/bson/value_reader_test.go index ed9beaaad9..852a291dd4 100644 --- a/bson/value_reader_test.go +++ b/bson/value_reader_test.go @@ -178,8 +178,8 @@ func TestValueReader(t *testing.T) { // invalid length vr.r = bufio.NewReader(bytes.NewReader([]byte{0x00, 0x00})) _, err := vr.ReadDocument() - if !errors.Is(err, io.EOF) { - t.Errorf("Expected io.EOF with document length too small. got %v; want %v", err, io.EOF) + if !errors.Is(err, io.ErrUnexpectedEOF) { + t.Errorf("Expected io.ErrUnexpectedEOF with document length too small. got %v; want %v", err, io.EOF) } if vr.offset != 0 { t.Errorf("Expected 0 offset. got %d", vr.offset) @@ -234,7 +234,7 @@ func TestValueReader(t *testing.T) { vr.frame-- _, err = vr.ReadDocument() - if !errors.Is(err, io.EOF) { + if !errors.Is(err, io.ErrUnexpectedEOF) { t.Errorf("Should return error when attempting to read length with not enough bytes. got %v; want %v", err, io.EOF) } }) @@ -778,7 +778,7 @@ func TestValueReader(t *testing.T) { append([]byte{0x40, 0x27, 0x00, 0x00}, testcstring...), (*valueReader).ReadString, "", - io.EOF, + io.ErrUnexpectedEOF, TypeString, }, { @@ -1417,7 +1417,7 @@ func TestValueReader(t *testing.T) { "append bytes", []byte{0x01, 0x02, 0x03, 0x04}, Type(0), - io.EOF, + io.ErrUnexpectedEOF, }, }