diff --git a/.golangci.yaml b/.golangci.yaml index fd1526d3e2..3e52c206dd 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -18,7 +18,6 @@ linters: - err113 - errcheck - errchkjson - - errname - errorlint - exhaustive - exhaustruct diff --git a/buildcontext/detectbuildfile.go b/buildcontext/detectbuildfile.go index 3dc3ef0a9e..5638934a6a 100644 --- a/buildcontext/detectbuildfile.go +++ b/buildcontext/detectbuildfile.go @@ -12,13 +12,13 @@ import ( "github.com/pkg/errors" ) -// ErrEarthfileNotExist is the struct indicating that file does not exist. -type ErrEarthfileNotExist struct { +// EarthfileNotExistError is the struct indicating that file does not exist. +type EarthfileNotExistError struct { Target string } -// Error is function required by error interface. -func (err ErrEarthfileNotExist) Error() string { +// Error implements [error] interface. +func (err EarthfileNotExistError) Error() string { return "No Earthfile nor build.earth file found for target " + err.Target } @@ -36,7 +36,7 @@ func detectBuildFile(ref domain.Reference, localDir string) (string, error) { _, err = os.Stat(buildEarthPath) if os.IsNotExist(err) { - return "", ErrEarthfileNotExist{Target: ref.String()} + return "", EarthfileNotExistError{Target: ref.String()} } else if err != nil { return "", errors.Wrapf(err, "stat file %s", buildEarthPath) } @@ -78,7 +78,7 @@ func detectBuildFileInRef( return buildEarthPath, nil } - return "", ErrEarthfileNotExist{Target: earthlyRef.String()} + return "", EarthfileNotExistError{Target: earthlyRef.String()} } func fileExists(ctx context.Context, ref gwclient.Reference, fpath string) (bool, error) { diff --git a/cmd/earthly/subcmd/ls_cmds.go b/cmd/earthly/subcmd/ls_cmds.go index f69a8a8920..72bc8993cf 100644 --- a/cmd/earthly/subcmd/ls_cmds.go +++ b/cmd/earthly/subcmd/ls_cmds.go @@ -86,11 +86,14 @@ func (a *List) action(cliCtx *cli.Context) error { // TODO this is a nil pointer which causes a panic if we try to expand a remotelyreferenced earthfile // it's expensive to create this gwclient, so we need to implement a lazy eval which returns it when required. - var gwClient gwclient.Client + var ( + gwClient gwclient.Client + notExistErr buildcontext.EarthfileNotExistError + ) // the +base is required to make ParseTarget work; however is ignored by GetTargets target, err := domain.ParseTarget(targetToParse + "+base") - if errors.Is(err, buildcontext.ErrEarthfileNotExist{}) { + if errors.As(err, ¬ExistErr) { return errors.Errorf("unable to locate Earthfile under %s", targetToDisplay) } else if err != nil { return err @@ -98,12 +101,11 @@ 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: + if errors.As(errors.Cause(err), ¬ExistErr) { return errors.Errorf("unable to locate Earthfile under %s", targetToDisplay) - default: - return err } + + return err } targets = append(targets, ast.TargetBase) diff --git a/earthfile2llb/converter.go b/earthfile2llb/converter.go index 18f099e1eb..6a1d877a9f 100644 --- a/earthfile2llb/converter.go +++ b/earthfile2llb/converter.go @@ -3445,7 +3445,7 @@ func (c *Converter) expandWildcardTargets(ctx context.Context, fullTargetName st data, _, _, err := c.ResolveReference(ctx, childTarget) if err != nil { - notExist := buildcontext.ErrEarthfileNotExist{} + notExist := buildcontext.EarthfileNotExistError{} if errors.As(err, ¬Exist) { continue } diff --git a/earthfile2llb/interpretererror.go b/earthfile2llb/interpretererror.go index c6de56c7df..ba9d925b16 100644 --- a/earthfile2llb/interpretererror.go +++ b/earthfile2llb/interpretererror.go @@ -49,6 +49,7 @@ func WrapError( } } +// Error implements [error] interface. func (ie InterpreterError) Error() string { var err error if ie.cause != nil { diff --git a/inputgraph/error.go b/inputgraph/error.go index 41f2e1b377..3ddfa7c9b7 100644 --- a/inputgraph/error.go +++ b/inputgraph/error.go @@ -16,6 +16,7 @@ type Error struct { msg string } +// Error implements [error] interface. func (e *Error) Error() string { parts := []string{} if e.msg != "" { diff --git a/util/cliutil/earthlydir.go b/util/cliutil/earthlydir.go index 3a327d9adc..abeb13d2c4 100644 --- a/util/cliutil/earthlydir.go +++ b/util/cliutil/earthlydir.go @@ -18,7 +18,7 @@ var ( var ( earthlyDirCreateOnce sync.Once - earthlyDirCreateErr error + errEarthlyDirCreate error ) // GetEarthlyDir returns the .earthly dir. (Usually ~/.earthly). @@ -51,27 +51,27 @@ func GetOrCreateEarthlyDir(installName string) (string, error) { earthlyDirCreateOnce.Do(func() { earthlyDirExists, err := fileutil.DirExists(earthlyDir) if err != nil { - earthlyDirCreateErr = errors.Wrapf(err, "unable to create dir %s", earthlyDir) + errEarthlyDirCreate = errors.Wrapf(err, "unable to create dir %s", earthlyDir) return } if !earthlyDirExists { err := os.MkdirAll(earthlyDir, 0o755) // #nosec G301 if err != nil { - earthlyDirCreateErr = errors.Wrapf(err, "unable to create dir %s", earthlyDir) + errEarthlyDirCreate = errors.Wrapf(err, "unable to create dir %s", earthlyDir) return } if earthlyDirSudoUser != nil { err := fileutil.EnsureUserOwned(earthlyDir, earthlyDirSudoUser) if err != nil { - earthlyDirCreateErr = errors.Wrapf(err, "failed to ensure %s is owned by %s", earthlyDir, earthlyDirSudoUser) + errEarthlyDirCreate = errors.Wrapf(err, "failed to ensure %s is owned by %s", earthlyDir, earthlyDirSudoUser) } } } }) - return earthlyDir, earthlyDirCreateErr + return earthlyDir, errEarthlyDirCreate } // IsBootstrapped provides a tentatively correct guess about the state of our bootstrapping. diff --git a/util/hint/hinterror.go b/util/hint/hinterror.go index ba9ebceb26..f260e1c3f2 100644 --- a/util/hint/hinterror.go +++ b/util/hint/hinterror.go @@ -18,7 +18,7 @@ type Error struct { hints []string } -// Error returns the error string. +// Error implements [error] interface. func (e *Error) Error() string { return fmt.Sprintf(`%v:Hint: %v`, e.err, e.Hint()) } diff --git a/util/params/paramerror.go b/util/params/paramerror.go index 31efc8e965..8780ece15b 100644 --- a/util/params/paramerror.go +++ b/util/params/paramerror.go @@ -24,6 +24,7 @@ func Wrapf(err error, format string, args ...any) error { } } +// Error implements [error] interface. func (e *Error) Error() string { if e.cause != nil { return fmt.Errorf("%s: %w", e.msg, e.cause).Error()