Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ linters:
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- exhaustruct
- fatcontext
Expand Down
4 changes: 3 additions & 1 deletion buildcontext/excludes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"path/filepath"
"reflect"
"testing"

"github.com/pkg/errors"
)

func Test_readExcludes(t *testing.T) {
Expand Down Expand Up @@ -122,7 +124,7 @@ func Test_readExcludes(t *testing.T) {
}

excludes, err := readExcludes(dir, testcase.noImplicitIgnore, testcase.useDockerIgnore)
if err != testcase.expectedErr {
if !errors.Is(err, testcase.expectedErr) {
t.Logf("actual err: %v", err)
t.Logf("expected err: %v", testcase.expectedErr)
t.Error("unexpected error getting excludes")
Expand Down
7 changes: 3 additions & 4 deletions buildcontext/gitlookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,11 @@ func (gl *GitLookup) getHostKeyAlgorithms(hostname string) ([]string, []string,
} {
for _, keyScan := range keyScans {
keyAlg, keyData, err := parseKeyScanIfHostMatches(keyScan, hostname)
switch err {
case nil:
case errKeyScanNoMatch:
switch {
case errors.Is(err, errKeyScanNoMatch):
gl.console.VerbosePrintf("ignoring key scan %q: due to host mismatch", keyScan)
continue
default:
case err != nil:
gl.console.Warnf("failed to parse key scan %q: %s", keyScan, err)
continue
}
Expand Down
10 changes: 5 additions & 5 deletions builder/image_solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ func (s *tarImageSolver) SolveImage(
buf := make([]byte, 1024)
for {
n, err := pipeR.Read(buf)
if err != nil && err != io.EOF {
return errors.Wrap(err, "pipe read")
}
if err != nil {
if errors.Is(err, io.EOF) {
break
}

if err == io.EOF {
break
return errors.Wrap(err, "pipe read")
}

_, err = bufFile.Write(buf[:n])
Expand Down
11 changes: 8 additions & 3 deletions cmd/debugger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func sendFile(ctx context.Context, sockAddr, src, dst string) error {
for {
n, err := r.Read(b[:cap(b)])
if err != nil {
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}

Expand Down Expand Up @@ -384,7 +384,9 @@ func main() {

exitCode = 127

if exitErr, ok := err.(*exec.ExitError); ok {
var exitErr *exec.ExitError

if errors.As(err, &exitErr) {
exitCode = exitErr.ExitCode()
}
}
Expand Down Expand Up @@ -416,7 +418,10 @@ func handleError(
quotedCmd := shellescape.QuoteCommand(args)

exitCode := 1
if exitErr, ok := err.(*exec.ExitError); ok {

var exitErr *exec.ExitError

if errors.As(err, &exitErr) {
exitCode = exitErr.ExitCode()
if debuggerSettings.Enabled {
conslogger.Warnf("Command %s failed with exit code %d\n", quotedCmd, exitCode)
Expand Down
9 changes: 5 additions & 4 deletions cmd/earthly/subcmd/ls_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ func (a *List) action(cliCtx *cli.Context) error {

targets, err := earthfile2llb.GetTargets(cliCtx.Context, resolver, gwClient, target)
if err != nil {
switch err := errors.Cause(err).(type) {
case *buildcontext.ErrEarthfileNotExist:
var errEarthfileNotExist *buildcontext.ErrEarthfileNotExist

if errors.As(err, &errEarthfileNotExist) {
return errors.Errorf("unable to locate Earthfile under %s", targetToDisplay)
default:
return err
}

return err
}

targets = append(targets, ast.TargetBase)
Expand Down
2 changes: 1 addition & 1 deletion debugger/terminal/terminal_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func ConnectTerm(ctx context.Context, conn io.ReadWriteCloser, console consloggi
for {
connDataType, data, err := common.ReadDataPacket(conn)
if err != nil {
if err != io.EOF {
if !errors.Is(err, io.EOF) {
console.VerbosePrintf("ReadDataPacket failed: %s\n", err.Error())
}

Expand Down
7 changes: 4 additions & 3 deletions earthfile2llb/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2661,12 +2661,13 @@ func (c *Converter) internalRun(ctx context.Context, opts ConvertRunOpts) (pllb.
// Debugger.
err = c.opt.LLBCaps.Supports(solverpb.CapExecMountSock)
if err != nil {
switch errors.Cause(err).(type) {
case *apicaps.CapError:
var capErr *apicaps.CapError

if errors.As(err, &capErr) {
if c.opt.InteractiveDebuggerEnabled || isInteractive {
return pllb.State{}, errors.Wrap(err, "interactive debugger requires a newer version of buildkit")
}
default:
} else {
c.opt.Console.Warnf("failed to check LLBCaps for CapExecMountSock: %v", err) // keep going
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions earthfile2llb/interpretererror.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func GetInterpreterError(err error) (*InterpreterError, bool) {
return nil, false
}

ie, ok := err.(*InterpreterError)
if ok {
var ie *InterpreterError
if errors.As(err, &ie) {
return ie, true
}

Expand Down
6 changes: 4 additions & 2 deletions logbus/solvermon/vertexmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ func determineFatalErrorType(errString string, exitCode int, exitParseErr error)
return logstream.FailureType_FAILURE_TYPE_UNKNOWN, false
}

if exitParseErr == errNoExitCodeOMM {
if errors.Is(exitParseErr, errNoExitCodeOMM) {
return logstream.FailureType_FAILURE_TYPE_OOM_KILLED, true
} else if exitParseErr != nil && exitParseErr != errNoExitCode {
}

if exitParseErr != nil && !errors.Is(exitParseErr, errNoExitCode) {
// We have an exit code, and can't parse it
return logstream.FailureType_FAILURE_TYPE_UNKNOWN, true
}
Expand Down
2 changes: 1 addition & 1 deletion logbus/solvermon/vertexmon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestGetExitCode(t *testing.T) {
t.Errorf("getExitCode(%q) = %d, want %d", tt.errString, code, tt.expectedCode)
}

if err != tt.expectedError {
if !errors.Is(err, tt.expectedError) {
t.Errorf("getExitCode(%q) = %d, want %d", tt.errString, err, tt.expectedError)
}
})
Expand Down
10 changes: 6 additions & 4 deletions util/buildkitskipper/hasher/hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"crypto/sha1" // #nosec G505
"encoding/json"
"errors"
"fmt"
"hash"
"io"
Expand Down Expand Up @@ -87,13 +88,14 @@ func (h *Hasher) HashFile(ctx context.Context, src string) error {

select {
case err := <-readCh:
if err == io.EOF {
switch {
case errors.Is(err, io.EOF):
return nil
} else if err != nil {
case err != nil:
return err
default:
h.h.Write(buf[:n])
}

h.h.Write(buf[:n])
case <-ctx.Done():
return ctx.Err()
}
Expand Down
12 changes: 6 additions & 6 deletions util/gitutil/detectgit.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ func detectGitTimestamp(ctx context.Context, dir string, tsType gitTimestampType

out, err := cmd.Output()
if err != nil {
exitError, ok := err.(*exec.ExitError)
if ok && strings.Contains(string(exitError.Stderr), "does not have any commits yet") {
var exitError *exec.ExitError
if errors.As(err, &exitError) && strings.Contains(string(exitError.Stderr), "does not have any commits yet") {
return "", nil
}

Expand All @@ -410,8 +410,8 @@ func detectGitAuthor(ctx context.Context, dir string, format string) (string, er

out, err := cmd.Output()
if err != nil {
exitError, ok := err.(*exec.ExitError)
if ok && strings.Contains(string(exitError.Stderr), "does not have any commits yet") {
var exitError *exec.ExitError
if errors.As(err, &exitError) && strings.Contains(string(exitError.Stderr), "does not have any commits yet") {
return "", nil
}

Expand Down Expand Up @@ -446,8 +446,8 @@ func detectGitCoAuthors(ctx context.Context, dir string) ([]string, error) {

out, err := cmd.Output()
if err != nil {
exitError, ok := err.(*exec.ExitError)
if ok && strings.Contains(string(exitError.Stderr), "does not have any commits yet") {
var exitError *exec.ExitError
if errors.As(err, &exitError) && strings.Contains(string(exitError.Stderr), "does not have any commits yet") {
return nil, nil
}

Expand Down
12 changes: 5 additions & 7 deletions util/gitutil/detectgitbinary_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ package gitutil

import (
"context"
"errors"
"os/exec"
)

func detectGitBinary(ctx context.Context) error {
cmd := exec.CommandContext(ctx, "/bin/sh", "-c", "which git")

_, err := cmd.Output()
if err != nil {
_, isExitError := err.(*exec.ExitError)
if isExitError {
return ErrNoGitBinary
}

return err
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
return ErrNoGitBinary
}

return nil
return err
}
5 changes: 3 additions & 2 deletions util/gitutil/detectgitbinary_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ package gitutil

import (
"context"
"errors"
"os/exec"
)

func detectGitBinary(ctx context.Context) error {
cmd := exec.CommandContext(ctx, "cmd", "/C", "where git")
_, err := cmd.Output()
if err != nil {
_, isExitError := err.(*exec.ExitError)
if isExitError {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
return ErrNoGitBinary
}
return err
Expand Down
6 changes: 3 additions & 3 deletions util/llbutil/secretprovider/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ func (c *cmdStore) GetSecret(ctx context.Context, id string) ([]byte, error) {
}

func (c *cmdStore) secretNotFound(err error) error {
exiterr, ok := err.(*exec.ExitError)
if !ok {
var exitErr *exec.ExitError
if !errors.As(err, &exitErr) {
return err
}

status, ok := exiterr.Sys().(syscall.WaitStatus)
status, ok := exitErr.Sys().(syscall.WaitStatus)
if !ok {
return err
}
Expand Down
24 changes: 16 additions & 8 deletions util/params/paramerror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ func TestError(t *testing.T) {
func TestCause(t *testing.T) {
t.Parallel()

pe, _ := Wrapf(internal, "some error").(*Error)
res := pe.Cause()
var err *Error

assert.True(t, errors.As(Wrapf(internal, "some error"), &err))
res := err.Cause()
assert.Equal(t, errors.Cause(internal), res)
}

Expand All @@ -84,23 +86,29 @@ func TestIs(t *testing.T) {
t.Run("non param error", func(t *testing.T) {
t.Parallel()

pe, _ := Errorf("some error").(*Error)
res := pe.Is(internal)
var err *Error

assert.True(t, errors.As(Wrapf(internal, "some error"), &err))
res := err.Is(internal)
assert.False(t, res)
})
t.Run("param error", func(t *testing.T) {
t.Parallel()

pe, _ := Errorf("some error").(*Error)
res := pe.Is(pe)
var err *Error

assert.True(t, errors.As(Wrapf(internal, "some error"), &err))
res := err.Is(err)
assert.True(t, res)
})
}

func TestParentError(t *testing.T) {
t.Parallel()

pe, _ := Wrapf(internal, "some error").(*Error)
res := pe.ParentError()
var err *Error

assert.True(t, errors.As(Wrapf(internal, "some error"), &err))
res := err.ParentError()
assert.Equal(t, "some error", res)
}
2 changes: 1 addition & 1 deletion util/semverutil/semverutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Parse(s string) (Version, error) {
var v Version

n, err := fmt.Sscanf(s, "%d.%d.%d%s", &v.Major, &v.Minor, &v.Patch, &v.Tail)
if err == io.EOF && n == 3 { // no tail case
if errors.Is(err, io.EOF) && n == 3 { // no tail case
return v, nil
}

Expand Down
Loading
Loading