Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -18,7 +18,6 @@ linters:
- err113
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- exhaustruct
Expand Down
12 changes: 6 additions & 6 deletions buildcontext/detectbuildfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/earthly/subcmd/ls_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (a *List) action(cliCtx *cli.Context) error {

// 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.Is(err, buildcontext.EarthfileNotExistError{}) {
return errors.Errorf("unable to locate Earthfile under %s", targetToDisplay)
} else if err != nil {
return err
Expand All @@ -99,7 +99,7 @@ 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:
case *buildcontext.EarthfileNotExistError:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The EarthfileNotExistError is returned as a value, not a pointer, in buildcontext/detectbuildfile.go. This type switch should therefore check for the value type buildcontext.EarthfileNotExistError instead of the pointer type *buildcontext.EarthfileNotExistError to correctly handle the error.

Suggested change
case *buildcontext.EarthfileNotExistError:
case buildcontext.EarthfileNotExistError:

return errors.Errorf("unable to locate Earthfile under %s", targetToDisplay)
default:
return err
Expand Down
2 changes: 1 addition & 1 deletion earthfile2llb/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3430,7 +3430,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, &notExist) {
continue
}
Expand Down
1 change: 1 addition & 0 deletions earthfile2llb/interpretererror.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func WrapError(
}
}

// Error implements [error] interface.
func (ie InterpreterError) Error() string {
var err error
if ie.cause != nil {
Expand Down
1 change: 1 addition & 0 deletions inputgraph/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Error struct {
msg string
}

// Error implements [error] interface.
func (e *Error) Error() string {
parts := []string{}
if e.msg != "" {
Expand Down
10 changes: 5 additions & 5 deletions util/cliutil/earthlydir.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (

var (
earthlyDirCreateOnce sync.Once
earthlyDirCreateErr error
errEarthlyDirCreate error
)

// GetEarthlyDir returns the .earthly dir. (Usually ~/.earthly).
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion util/hint/hinterror.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
1 change: 1 addition & 0 deletions util/params/paramerror.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading