mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 13:44:05 -08:00
Use errors.Is to check for a specific error
Signed-off-by: Fish-pro <zechun.chen@daocloud.io>
This commit is contained in:
parent
49f775d8a0
commit
6ed71a229e
|
@ -16,6 +16,7 @@ package textparse
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -604,7 +605,7 @@ metric: <
|
||||||
|
|
||||||
for {
|
for {
|
||||||
et, err := p.Next()
|
et, err := p.Next()
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -1544,7 +1544,7 @@ loop:
|
||||||
fh *histogram.FloatHistogram
|
fh *histogram.FloatHistogram
|
||||||
)
|
)
|
||||||
if et, err = p.Next(); err != nil {
|
if et, err = p.Next(); err != nil {
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
|
@ -15,6 +15,7 @@ package remote
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -163,7 +164,7 @@ func BenchmarkStreamReadEndpoint(b *testing.B) {
|
||||||
for {
|
for {
|
||||||
res := &prompb.ChunkedReadResponse{}
|
res := &prompb.ChunkedReadResponse{}
|
||||||
err := stream.NextProto(res)
|
err := stream.NextProto(res)
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
|
@ -253,7 +254,7 @@ func TestStreamReadEndpoint(t *testing.T) {
|
||||||
for {
|
for {
|
||||||
res := &prompb.ChunkedReadResponse{}
|
res := &prompb.ChunkedReadResponse{}
|
||||||
err := stream.NextProto(res)
|
err := stream.NextProto(res)
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -667,7 +667,7 @@ func (h *Head) Init(minValidTime int64) error {
|
||||||
offset = snapOffset
|
offset = snapOffset
|
||||||
}
|
}
|
||||||
sr, err := wlog.NewSegmentBufReaderWithOffset(offset, s)
|
sr, err := wlog.NewSegmentBufReaderWithOffset(offset, s)
|
||||||
if errors.Cause(err) == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
// File does not exist.
|
// File does not exist.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -1018,7 +1018,7 @@ func (r *walReader) next() bool {
|
||||||
// If we reached the end of the reader, advance to the next one
|
// If we reached the end of the reader, advance to the next one
|
||||||
// and close.
|
// and close.
|
||||||
// Do not close on the last one as it will still be appended to.
|
// 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 {
|
if r.cur == len(r.files)-1 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ type LiveReader struct {
|
||||||
// not be used again. It is up to the user to decide when to stop trying should
|
// not be used again. It is up to the user to decide when to stop trying should
|
||||||
// io.EOF be returned.
|
// io.EOF be returned.
|
||||||
func (r *LiveReader) Err() error {
|
func (r *LiveReader) Err() error {
|
||||||
if r.eofNonErr && r.err == io.EOF {
|
if r.eofNonErr && errors.Is(r.err, io.EOF) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return r.err
|
return r.err
|
||||||
|
|
|
@ -43,7 +43,7 @@ func NewReader(r io.Reader) *Reader {
|
||||||
// It must not be called again after it returned false.
|
// It must not be called again after it returned false.
|
||||||
func (r *Reader) Next() bool {
|
func (r *Reader) Next() bool {
|
||||||
err := r.next()
|
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 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 would be torn after a crash just before
|
||||||
// the last record part could be persisted to disk.
|
// the last record part could be persisted to disk.
|
||||||
|
|
Loading…
Reference in a new issue