Use errors.Is to check for a specific error

Signed-off-by: Fish-pro <zechun.chen@daocloud.io>
This commit is contained in:
Fish-pro 2022-12-29 23:23:07 +08:00
parent 49f775d8a0
commit 6ed71a229e
7 changed files with 10 additions and 8 deletions

View File

@ -16,6 +16,7 @@ package textparse
import (
"bytes"
"encoding/binary"
"errors"
"io"
"testing"
@ -604,7 +605,7 @@ metric: <
for {
et, err := p.Next()
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
require.NoError(t, err)

View File

@ -1544,7 +1544,7 @@ loop:
fh *histogram.FloatHistogram
)
if et, err = p.Next(); err != nil {
if err == io.EOF {
if errors.Is(err, io.EOF) {
err = nil
}
break

View File

@ -15,6 +15,7 @@ package remote
import (
"bytes"
"errors"
"io"
"net/http"
"net/http/httptest"
@ -163,7 +164,7 @@ func BenchmarkStreamReadEndpoint(b *testing.B) {
for {
res := &prompb.ChunkedReadResponse{}
err := stream.NextProto(res)
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
require.NoError(b, err)
@ -253,7 +254,7 @@ func TestStreamReadEndpoint(t *testing.T) {
for {
res := &prompb.ChunkedReadResponse{}
err := stream.NextProto(res)
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
require.NoError(t, err)

View File

@ -667,7 +667,7 @@ func (h *Head) Init(minValidTime int64) error {
offset = snapOffset
}
sr, err := wlog.NewSegmentBufReaderWithOffset(offset, s)
if errors.Cause(err) == io.EOF {
if errors.Is(err, io.EOF) {
// File does not exist.
continue
}

View File

@ -1018,7 +1018,7 @@ func (r *walReader) next() bool {
// If we reached the end of the reader, advance to the next one
// and close.
// Do not close on the last one as it will still be appended to.
if err == io.EOF {
if errors.Is(err, io.EOF) {
if r.cur == len(r.files)-1 {
return false
}

View File

@ -96,7 +96,7 @@ type LiveReader struct {
// not be used again. It is up to the user to decide when to stop trying should
// io.EOF be returned.
func (r *LiveReader) Err() error {
if r.eofNonErr && r.err == io.EOF {
if r.eofNonErr && errors.Is(r.err, io.EOF) {
return nil
}
return r.err

View File

@ -43,7 +43,7 @@ func NewReader(r io.Reader) *Reader {
// It must not be called again after it returned false.
func (r *Reader) Next() bool {
err := r.next()
if errors.Cause(err) == io.EOF {
if errors.Is(err, io.EOF) {
// The last WAL segment record shouldn't be torn(should be full or last).
// The last record would be torn after a crash just before
// the last record part could be persisted to disk.