diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-12-14 01:36:26 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-01-24 15:24:39 +0300 |
commit | 933c033f153891f5e338b8463b3b8f3c91d8885e (patch) | |
tree | ef7c6e74878a87df4449de897aa1fe1c845a51af /internal | |
parent | c27b7ef86e28c9e97c5c655a958bdb733aca01eb (diff) |
lint: fix errorlint issues
Diffstat (limited to 'internal')
-rw-r--r-- | internal/httprange/http_ranged_reader_test.go | 3 | ||||
-rw-r--r-- | internal/httprange/http_reader.go | 2 | ||||
-rw-r--r-- | internal/serving/disk/reader.go | 8 | ||||
-rw-r--r-- | internal/vfs/zip/archive.go | 7 | ||||
-rw-r--r-- | internal/vfs/zip/vfs_test.go | 3 |
5 files changed, 13 insertions, 10 deletions
diff --git a/internal/httprange/http_ranged_reader_test.go b/internal/httprange/http_ranged_reader_test.go index d32e5619..22f2b094 100644 --- a/internal/httprange/http_ranged_reader_test.go +++ b/internal/httprange/http_ranged_reader_test.go @@ -2,6 +2,7 @@ package httprange import ( "context" + "errors" "io" "net/http" "net/http/httptest" @@ -95,7 +96,7 @@ func TestSectionReader(t *testing.T) { buf := make([]byte, tt.readSize) n, err := s.Read(buf) - if tt.expectedErr != nil && err != io.EOF { + if tt.expectedErr != nil && !errors.Is(err, io.EOF) { require.EqualError(t, err, tt.expectedErr.Error()) return } diff --git a/internal/httprange/http_reader.go b/internal/httprange/http_reader.go index c2b81b4d..639d391f 100644 --- a/internal/httprange/http_reader.go +++ b/internal/httprange/http_reader.go @@ -171,7 +171,7 @@ func (r *Reader) Read(buf []byte) (int, error) { } n, err := r.res.Body.Read(buf) - if err == nil || err == io.EOF { + if err == nil || errors.Is(err, io.EOF) { r.offset += int64(n) } diff --git a/internal/serving/disk/reader.go b/internal/serving/disk/reader.go index 5961d843..4078d5ef 100644 --- a/internal/serving/disk/reader.go +++ b/internal/serving/disk/reader.go @@ -50,7 +50,7 @@ func (reader *Reader) tryRedirects(h serving.Handler) bool { rewrittenURL, status, err := r.Rewrite(h.Request.URL) if err != nil { - if err != redirects.ErrNoRedirect { + if !errors.Is(err, redirects.ErrNoRedirect) { // We assume that rewrite failure is not fatal // and we only capture the error errortracking.Capture(err, errortracking.WithRequest(h.Request), errortracking.WithStackTrace()) @@ -81,7 +81,8 @@ func (reader *Reader) tryFile(h serving.Handler) bool { request := h.Request urlPath := request.URL.Path - if locationError, _ := err.(*locationDirectoryError); locationError != nil { + var locationDirError *locationDirectoryError + if errors.As(err, &locationDirError) { if endsWithSlash(urlPath) { fullPath, err = reader.resolvePath(ctx, root, h.SubPath, "index.html") } else { @@ -90,7 +91,8 @@ func (reader *Reader) tryFile(h serving.Handler) bool { } } - if locationError, _ := err.(*locationFileNoExtensionError); locationError != nil { + var locationFileError *locationFileNoExtensionError + if errors.As(err, &locationFileError) { fullPath, err = reader.resolvePath(ctx, root, strings.TrimSuffix(h.SubPath, "/")+".html") } diff --git a/internal/vfs/zip/archive.go b/internal/vfs/zip/archive.go index b773899c..c44f45ef 100644 --- a/internal/vfs/zip/archive.go +++ b/internal/vfs/zip/archive.go @@ -100,10 +100,9 @@ func (a *zipArchive) openArchive(parentCtx context.Context, url string) (err err return a.err case <-ctx.Done(): err := ctx.Err() - switch err { - case context.Canceled: + if errors.Is(err, context.Canceled) { log.ContextLogger(parentCtx).WithError(err).Traceln("open zip archive request canceled") - case context.DeadlineExceeded: + } else if errors.Is(err, context.DeadlineExceeded) { log.ContextLogger(parentCtx).WithError(err).Traceln("open zip archive timed out") } @@ -264,7 +263,7 @@ func (a *zipArchive) Readlink(ctx context.Context, name string) (string, error) // read up to len(symlink) bytes from the link file n, err := io.ReadFull(rc, link[:]) - if err != nil && err != io.ErrUnexpectedEOF { + if err != nil && !errors.Is(err, io.ErrUnexpectedEOF) { // if err == io.ErrUnexpectedEOF the link is smaller than len(symlink) so it's OK to not return it return nil, err } diff --git a/internal/vfs/zip/vfs_test.go b/internal/vfs/zip/vfs_test.go index 98660719..4de0240a 100644 --- a/internal/vfs/zip/vfs_test.go +++ b/internal/vfs/zip/vfs_test.go @@ -2,6 +2,7 @@ package zip import ( "context" + "errors" "io" "io/fs" "testing" @@ -103,7 +104,7 @@ func TestVFSFindOrOpenArchiveConcurrentAccess(t *testing.T) { require.Eventually(t, func() bool { _, err := vfs.findOrOpenArchive(context.Background(), key, path) - return err == errAlreadyCached + return errors.Is(err, errAlreadyCached) }, 3*time.Second, time.Nanosecond) } |