Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use errors.New to replace fmt.Errorf with no parameters will much better #2301

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion pkg/artifactcache/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func StartHandler(dir, outboundIP string, port uint16, logger logrus.FieldLogger
if outboundIP != "" {
h.outboundIP = outboundIP
} else if ip := common.GetOutboundIP(); ip == nil {
return nil, fmt.Errorf("unable to determine outbound IP address")
return nil, errors.New("unable to determine outbound IP address")
} else {
h.outboundIP = ip.String()
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func FindGitRevision(ctx context.Context, file string) (shortSha string, sha str
}

if head.Hash().IsZero() {
return "", "", fmt.Errorf("HEAD sha1 could not be resolved")
return "", "", errors.New("HEAD sha1 could not be resolved")
}

hash := head.Hash().String()
Expand Down
8 changes: 4 additions & 4 deletions pkg/container/docker_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,16 +550,16 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
probe = strslice.StrSlice(args)
}
if copts.healthInterval < 0 {
return nil, errors.Errorf("--health-interval cannot be negative")
return nil, errors.New("--health-interval cannot be negative")
}
if copts.healthTimeout < 0 {
return nil, errors.Errorf("--health-timeout cannot be negative")
return nil, errors.New("--health-timeout cannot be negative")
}
if copts.healthRetries < 0 {
return nil, errors.Errorf("--health-retries cannot be negative")
return nil, errors.New("--health-retries cannot be negative")
}
if copts.healthStartPeriod < 0 {
return nil, fmt.Errorf("--health-start-period cannot be negative")
return nil, errors.New("--health-start-period cannot be negative")
}

healthConfig = &container.HealthConfig{
Expand Down
2 changes: 1 addition & 1 deletion pkg/container/docker_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (cr *containerReference) CopyDir(destPath string, srcPath string, useGitIgn

func (cr *containerReference) GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error) {
if common.Dryrun(ctx) {
return nil, fmt.Errorf("DRYRUN is not supported in GetContainerArchive")
return nil, errors.New("DRYRUN is not supported in GetContainerArchive")
}
a, _, err := cr.cli.CopyFromContainer(ctx, cr.id, srcPath)
return a, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/container/host_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (e *HostEnvironment) CopyTarStream(ctx context.Context, destPath string, ta
continue
}
if ctx.Err() != nil {
return fmt.Errorf("CopyTarStream has been cancelled")
return errors.New("CopyTarStream has been cancelled")
}
if err := cp.WriteFile(ti.Name, ti.FileInfo(), ti.Linkname, tr); err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion pkg/exprparser/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package exprparser

import (
"encoding"
"errors"
"fmt"
"math"
"reflect"
Expand Down Expand Up @@ -161,7 +162,7 @@ func (impl *interperterImpl) evaluateVariable(variableNode *actionlint.VariableN
return impl.env.Job, nil
case "jobs":
if impl.env.Jobs == nil {
return nil, fmt.Errorf("Unavailable context: jobs")
return nil, errors.New("Unavailable context: jobs")
}
return impl.env.Jobs, nil
case "steps":
Expand Down
3 changes: 2 additions & 1 deletion pkg/filecollector/file_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package filecollector
import (
"archive/tar"
"context"
"errors"
"fmt"
"io"
"io/fs"
Expand Down Expand Up @@ -134,7 +135,7 @@ func (fc *FileCollector) CollectFiles(ctx context.Context, submodulePath []strin
if ctx != nil {
select {
case <-ctx.Done():
return fmt.Errorf("copy cancelled")
return errors.New("copy cancelled")
default:
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/model/planner.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package model

import (
"errors"
"fmt"
"io"
"io/fs"
Expand Down Expand Up @@ -383,7 +384,7 @@ func createStages(w *Workflow, jobIDs ...string) ([]*Stage, error) {
}

if len(stages) == 0 {
return nil, fmt.Errorf("Could not find any stages to run. View the valid jobs with `act --list`. Use `act --help` to find how to filter by Job ID/Workflow/Event Name")
return nil, errors.New("Could not find any stages to run. View the valid jobs with `act --list`. Use `act --help` to find how to filter by Job ID/Workflow/Event Name")
}

return stages, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/runner/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ func runPreStep(step actionStep) common.Executor {
if steps := step.getCompositeSteps(); steps != nil && steps.pre != nil {
return steps.pre(ctx)
}
return fmt.Errorf("missing steps in composite action")
return errors.New("missing steps in composite action")

default:
return nil
Expand Down Expand Up @@ -641,7 +641,7 @@ func runPostStep(step actionStep) common.Executor {
if steps := step.getCompositeSteps(); steps != nil && steps.post != nil {
return steps.post(ctx)
}
return fmt.Errorf("missing steps in composite action")
return errors.New("missing steps in composite action")

default:
return nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/runner/action_composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package runner

import (
"context"
"errors"
"fmt"
"regexp"
"strings"
Expand Down Expand Up @@ -90,7 +91,7 @@ func execAsComposite(step actionStep) common.Executor {
steps := step.getCompositeSteps()

if steps == nil || steps.main == nil {
return fmt.Errorf("missing steps in composite action")
return errors.New("missing steps in composite action")
}

ctx = WithCompositeLogger(ctx, &compositeRC.Masks)
Expand Down
14 changes: 7 additions & 7 deletions pkg/runner/run_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -981,22 +981,22 @@ func (rc *RunContext) handleCredentials(ctx context.Context) (string, string, er
}

if container.Credentials != nil && len(container.Credentials) != 2 {
err := fmt.Errorf("invalid property count for key 'credentials:'")
err := errors.New("invalid property count for key 'credentials:'")
return "", "", err
}

ee := rc.NewExpressionEvaluator(ctx)
if username = ee.Interpolate(ctx, container.Credentials["username"]); username == "" {
err := fmt.Errorf("failed to interpolate container.credentials.username")
err := errors.New("failed to interpolate container.credentials.username")
return "", "", err
}
if password = ee.Interpolate(ctx, container.Credentials["password"]); password == "" {
err := fmt.Errorf("failed to interpolate container.credentials.password")
err := errors.New("failed to interpolate container.credentials.password")
return "", "", err
}

if container.Credentials["username"] == "" || container.Credentials["password"] == "" {
err := fmt.Errorf("container.credentials cannot be empty")
err := errors.New("container.credentials cannot be empty")
return "", "", err
}

Expand All @@ -1008,18 +1008,18 @@ func (rc *RunContext) handleServiceCredentials(ctx context.Context, creds map[st
return
}
if len(creds) != 2 {
err = fmt.Errorf("invalid property count for key 'credentials:'")
err = errors.New("invalid property count for key 'credentials:'")
return
}

ee := rc.NewExpressionEvaluator(ctx)
if username = ee.Interpolate(ctx, creds["username"]); username == "" {
err = fmt.Errorf("failed to interpolate credentials.username")
err = errors.New("failed to interpolate credentials.username")
return
}

if password = ee.Interpolate(ctx, creds["password"]); password == "" {
err = fmt.Errorf("failed to interpolate credentials.password")
err = errors.New("failed to interpolate credentials.password")
return
}

Expand Down