Skip to content

Commit

Permalink
stop using errors.Is to compare err and io.EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaodiaoer committed May 16, 2022
1 parent 0cbb948 commit 2a3a228
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/preflight/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (dac DirExistingCheck) Check() (warnings, errorList []error) {
defer f.Close()

_, err = f.Readdirnames(1)
if errors.Is(err, io.EOF) {
if err == io.EOF {
return nil, []error{errors.Errorf("%s is empty", dac.Path)}
}
return nil, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/yurtctl/kubernetes/kubeadm/app/preflight/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (dac DirAvailableCheck) Check() (warnings, errorList []error) {
defer f.Close()

_, err = f.Readdirnames(1)
if !errors.Is(err, io.EOF) {
if err != io.EOF {
return nil, []error{errors.Errorf("%s is not empty", dac.Path)}
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/yurtctl/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package util
import (
"archive/tar"
"compress/gzip"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -106,7 +105,7 @@ func Untar(tarFile, dest string) error {
for {
hdr, err := tr.Next()
if err != nil {
if errors.Is(err, io.EOF) {
if err == io.EOF {
return nil
}
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/yurthub/cachemanager/cache_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ func TestCacheWatchResponse(t *testing.T) {

if tt.expectResult.err && err == nil {
t.Errorf("expect err, but do not got err")
} else if err != nil && !errors.Is(err, io.EOF) {
} else if err != nil && err != io.EOF {
t.Errorf("failed to cache resposne, %v", err)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/yurthub/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func NewFilterReadCloser(
if dr.isWatch {
go func(req *http.Request, rc io.ReadCloser, ch chan watch.Event) {
err := handler.StreamResponseFilter(rc, ch)
if err != nil && !errors.Is(err, io.EOF) && !errors.Is(err, context.Canceled) {
if err != nil && err != io.EOF && !errors.Is(err, context.Canceled) {
klog.Errorf("filter(%s) watch response ended with error, %v", dr.ownerName, err)
}
}(req, rc, dr.ch)
Expand Down
2 changes: 1 addition & 1 deletion pkg/yurthub/proxy/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (rp *RemoteProxy) modifyResponse(resp *http.Response) error {
wrapPrc, _ := util.NewGZipReaderCloser(resp.Header, prc, req, "cache-manager")
go func(req *http.Request, prc io.ReadCloser, stopCh <-chan struct{}) {
err := rp.cacheMgr.CacheResponse(req, prc, stopCh)
if err != nil && !errors.Is(err, io.EOF) && !errors.Is(err, context.Canceled) {
if err != nil && err != io.EOF && !errors.Is(err, context.Canceled) {
klog.Errorf("%s response cache ended with error, %v", util.ReqString(req), err)
}
}(req, wrapPrc, rp.stopCh)
Expand Down
4 changes: 2 additions & 2 deletions pkg/yurthub/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ func TestDualReader(t *testing.T) {
t.Errorf("nr: bytes read = %q want %q", dst2, src)
}

if n, err := rc.Read(dst1); n != 0 || !errors.Is(err, io.EOF) {
if n, err := rc.Read(dst1); n != 0 || err != io.EOF {
t.Errorf("rc.Read at EOF = %d, %v want 0, EOF", n, err)
}

if err := rc.Close(); err != nil {
t.Errorf("rc.Close failed %v", err)
}

if n, err := prc.Read(dst1); n != 0 || !errors.Is(err, io.EOF) {
if n, err := prc.Read(dst1); n != 0 || err != io.EOF {
t.Errorf("nr.Read at EOF = %d, %v want 0, EOF", n, err)
}
}
Expand Down

0 comments on commit 2a3a228

Please sign in to comment.