Skip to content

Commit d402799

Browse files
authored
Replace errors.Wrap with %w (GoogleContainerTools#3860)
Signed-off-by: David Gageot <[email protected]>
1 parent d975320 commit d402799

File tree

155 files changed

+634
-700
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+634
-700
lines changed

cmd/skaffold/app/cmd/build.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ package cmd
1919
import (
2020
"bytes"
2121
"context"
22+
"fmt"
2223
"io"
2324
"io/ioutil"
2425

25-
"github.com/pkg/errors"
2626
"github.com/spf13/cobra"
2727
"github.com/spf13/pflag"
2828

@@ -71,18 +71,18 @@ func doBuild(ctx context.Context, out io.Writer) error {
7171
cmdOut := flags.BuildOutput{Builds: bRes}
7272
var buildOutput bytes.Buffer
7373
if err := buildFormatFlag.Template().Execute(&buildOutput, cmdOut); err != nil {
74-
return errors.Wrap(err, "executing template")
74+
return fmt.Errorf("executing template: %w", err)
7575
}
7676

7777
if quietFlag {
7878
if _, err := out.Write(buildOutput.Bytes()); err != nil {
79-
return errors.Wrap(err, "writing build output")
79+
return fmt.Errorf("writing build output: %w", err)
8080
}
8181
}
8282

8383
if buildOutputFlag != "" {
8484
if err := ioutil.WriteFile(buildOutputFlag, buildOutput.Bytes(), 0644); err != nil {
85-
return errors.Wrap(err, "writing build output to file")
85+
return fmt.Errorf("writing build output to file: %w", err)
8686
}
8787
}
8888
}

cmd/skaffold/app/cmd/cmd.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"os"
2424
"strings"
2525

26-
"github.com/pkg/errors"
2726
"github.com/sirupsen/logrus"
2827
"github.com/spf13/cobra"
2928
"github.com/spf13/pflag"
@@ -85,7 +84,7 @@ func NewSkaffoldCommand(out, err io.Writer) *cobra.Command {
8584
// Start API Server
8685
shutdown, err := server.Initialize(opts)
8786
if err != nil {
88-
return errors.Wrap(err, "initializing api server")
87+
return fmt.Errorf("initializing api server: %w", err)
8988
}
9089
shutdownAPIServer = shutdown
9190

@@ -191,7 +190,7 @@ func updateCheck(ch chan string, configfile string) error {
191190
}
192191
latest, current, err := update.GetLatestAndCurrentVersion()
193192
if err != nil {
194-
return errors.Wrap(err, "get latest and current Skaffold version")
193+
return fmt.Errorf("get latest and current Skaffold version: %w", err)
195194
}
196195
if latest.GT(current) {
197196
ch <- fmt.Sprintf("There is a new version (%s) of Skaffold available. Download it at %s\n", latest, constants.LatestDownloadURL)
@@ -233,7 +232,7 @@ func setUpLogs(stdErr io.Writer, level string) error {
233232
logrus.SetOutput(stdErr)
234233
lvl, err := logrus.ParseLevel(level)
235234
if err != nil {
236-
return errors.Wrap(err, "parsing log level")
235+
return fmt.Errorf("parsing log level: %w", err)
237236
}
238237
logrus.SetLevel(lvl)
239238
return nil

cmd/skaffold/app/cmd/config/list.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222
"io"
2323

24-
"github.com/pkg/errors"
2524
yaml "gopkg.in/yaml.v2"
2625

2726
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
@@ -39,7 +38,7 @@ func List(ctx context.Context, out io.Writer) error {
3938
}
4039
configYaml, err = yaml.Marshal(&cfg)
4140
if err != nil {
42-
return errors.Wrap(err, "marshaling config")
41+
return fmt.Errorf("marshaling config: %w", err)
4342
}
4443
} else {
4544
contextConfig, err := getConfigForKubectx()
@@ -51,7 +50,7 @@ func List(ctx context.Context, out io.Writer) error {
5150
}
5251
configYaml, err = yaml.Marshal(&contextConfig)
5352
if err != nil {
54-
return errors.Wrap(err, "marshaling config")
53+
return fmt.Errorf("marshaling config: %w", err)
5554
}
5655
}
5756

cmd/skaffold/app/cmd/config/set.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"strconv"
2626
"strings"
2727

28-
"github.com/pkg/errors"
2928
yaml "gopkg.in/yaml.v2"
3029

3130
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
@@ -166,15 +165,14 @@ func writeConfig(cfg *config.ContextConfig) error {
166165
func writeFullConfig(cfg *config.GlobalConfig) error {
167166
contents, err := yaml.Marshal(cfg)
168167
if err != nil {
169-
return errors.Wrap(err, "marshaling config")
168+
return fmt.Errorf("marshaling config: %w", err)
170169
}
171170
configFileOrDefault, err := config.ResolveConfigFile(configFile)
172171
if err != nil {
173172
return err
174173
}
175-
err = ioutil.WriteFile(configFileOrDefault, contents, 0644)
176-
if err != nil {
177-
return errors.Wrap(err, "writing config file")
174+
if err := ioutil.WriteFile(configFileOrDefault, contents, 0644); err != nil {
175+
return fmt.Errorf("writing config file: %w", err)
178176
}
179177
return nil
180178
}

cmd/skaffold/app/cmd/credits/export.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ package credits
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"io"
2223
"io/ioutil"
2324
"log"
2425
"os"
2526
"path"
2627
"path/filepath"
2728

28-
"github.com/pkg/errors"
2929
"github.com/rakyll/statik/fs"
3030

3131
"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/statik"
@@ -37,30 +37,29 @@ var Path string
3737
func Export(ctx context.Context, out io.Writer) error {
3838
statikFS, err := statik.FS()
3939
if err != nil {
40-
return errors.Wrap(err, "opening embedded filesystem")
40+
return fmt.Errorf("opening embedded filesystem: %w", err)
4141
}
4242

4343
if err := fs.Walk(statikFS, "/skaffold-credits", func(filePath string, fileInfo os.FileInfo, err error) error {
4444
newPath := path.Join(Path, "..", filePath)
4545
if fileInfo.IsDir() {
4646
err := os.Mkdir(newPath, 0755)
4747
if err != nil && !os.IsExist(err) {
48-
return errors.Wrapf(err, "creating directory %s", newPath)
48+
return fmt.Errorf("creating directory %q: %w", newPath, err)
4949
}
5050
} else {
5151
file, err := statikFS.Open(filePath)
5252
if err != nil {
53-
return errors.Wrapf(err, "opening %s in embedded filesystem", filePath)
53+
return fmt.Errorf("opening %q in embedded filesystem: %w", filePath, err)
5454
}
5555

5656
buf, err := ioutil.ReadAll(file)
5757
if err != nil {
58-
return errors.Wrapf(err, "reading %s in embedded filesystem", filePath)
58+
return fmt.Errorf("reading %q in embedded filesystem: %w", filePath, err)
5959
}
6060

61-
err = ioutil.WriteFile(newPath, buf, 0664)
62-
if err != nil {
63-
return errors.Wrapf(err, "writing %s to %s", filePath, newPath)
61+
if err := ioutil.WriteFile(newPath, buf, 0664); err != nil {
62+
return fmt.Errorf("writing %q to %q: %w", filePath, newPath, err)
6463
}
6564
}
6665
return nil

cmd/skaffold/app/cmd/dev.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ package cmd
1818

1919
import (
2020
"context"
21+
"errors"
2122
"io"
2223

23-
"github.com/pkg/errors"
2424
"github.com/sirupsen/logrus"
2525
"github.com/spf13/cobra"
2626
"github.com/spf13/pflag"
@@ -90,7 +90,7 @@ func doDev(ctx context.Context, out io.Writer) error {
9090
return err
9191
})
9292
if err != nil {
93-
if errors.Cause(err) != runner.ErrorConfigurationChanged {
93+
if !errors.Is(err, runner.ErrorConfigurationChanged) {
9494
return err
9595
}
9696
// Otherwise, the skaffold config has changed.

cmd/skaffold/app/cmd/diagnose.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222
"io"
2323

24-
"github.com/pkg/errors"
2524
"github.com/spf13/cobra"
2625
yaml "gopkg.in/yaml.v2"
2726

@@ -46,13 +45,13 @@ func doDiagnose(ctx context.Context, out io.Writer) error {
4645
fmt.Fprintln(out, "Number of artifacts:", len(config.Build.Artifacts))
4746

4847
if err := r.DiagnoseArtifacts(ctx, out); err != nil {
49-
return errors.Wrap(err, "running diagnostic on artifacts")
48+
return fmt.Errorf("running diagnostic on artifacts: %w", err)
5049
}
5150

5251
color.Blue.Fprintln(out, "\nConfiguration")
5352
buf, err := yaml.Marshal(config)
5453
if err != nil {
55-
return errors.Wrap(err, "marshalling configuration")
54+
return fmt.Errorf("marshalling configuration: %w", err)
5655
}
5756
out.Write(buf)
5857

cmd/skaffold/app/cmd/fix.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ package cmd
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"io"
2223
"io/ioutil"
2324

24-
"github.com/pkg/errors"
2525
"github.com/spf13/cobra"
2626
"github.com/spf13/pflag"
2727
yaml "gopkg.in/yaml.v2"
@@ -63,17 +63,17 @@ func fix(out io.Writer, configFile string, overwrite bool) error {
6363
}
6464

6565
if err := validation.Process(cfg.(*latest.SkaffoldConfig)); err != nil {
66-
return errors.Wrap(err, "validating upgraded config")
66+
return fmt.Errorf("validating upgraded config: %w", err)
6767
}
6868

6969
newCfg, err := yaml.Marshal(cfg)
7070
if err != nil {
71-
return errors.Wrap(err, "marshaling new config")
71+
return fmt.Errorf("marshaling new config: %w", err)
7272
}
7373

7474
if overwrite {
7575
if err := ioutil.WriteFile(configFile, newCfg, 0644); err != nil {
76-
return errors.Wrap(err, "writing config file")
76+
return fmt.Errorf("writing config file: %w", err)
7777
}
7878
color.Default.Fprintf(out, "New config at version %s generated and written to %s\n", cfg.GetVersion(), opts.ConfigurationFile)
7979
} else {

cmd/skaffold/app/cmd/generate_pipeline.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ package cmd
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"io"
2223

23-
"github.com/pkg/errors"
2424
"github.com/spf13/cobra"
2525
"github.com/spf13/pflag"
2626

@@ -47,7 +47,7 @@ func NewCmdGeneratePipeline() *cobra.Command {
4747
func doGeneratePipeline(ctx context.Context, out io.Writer) error {
4848
return withRunner(ctx, func(r runner.Runner, config *latest.SkaffoldConfig) error {
4949
if err := r.GeneratePipeline(ctx, out, config, configFiles, "pipeline.yaml"); err != nil {
50-
return errors.Wrap(err, "generating ")
50+
return fmt.Errorf("generating : %w", err)
5151
}
5252
color.Default.Fprintln(out, "Pipeline config written to pipeline.yaml!")
5353
return nil

cmd/skaffold/app/cmd/render.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ package cmd
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"io"
2223
"io/ioutil"
2324

24-
"github.com/pkg/errors"
2525
"github.com/spf13/cobra"
2626
"github.com/spf13/pflag"
2727

@@ -56,11 +56,11 @@ func doRender(ctx context.Context, out io.Writer) error {
5656
bRes, err := r.BuildAndTest(ctx, buildOut, targetArtifacts(opts, config))
5757

5858
if err != nil {
59-
return errors.Wrap(err, "executing build")
59+
return fmt.Errorf("executing build: %w", err)
6060
}
6161

6262
if err := r.Render(ctx, out, bRes, renderOutputPath); err != nil {
63-
return errors.Wrap(err, "rendering manifests")
63+
return fmt.Errorf("rendering manifests: %w", err)
6464
}
6565
return nil
6666
})

cmd/skaffold/app/cmd/run.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ package cmd
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"io"
2223

23-
"github.com/pkg/errors"
2424
"github.com/spf13/cobra"
2525

2626
"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/tips"
@@ -43,7 +43,7 @@ func doRun(ctx context.Context, out io.Writer) error {
4343
return withRunner(ctx, func(r runner.Runner, config *latest.SkaffoldConfig) error {
4444
bRes, err := r.BuildAndTest(ctx, out, config.Build.Artifacts)
4545
if err != nil {
46-
return errors.Wrap(err, "failed to build")
46+
return fmt.Errorf("failed to build: %w", err)
4747
}
4848

4949
err = r.DeployAndLog(ctx, out, bRes)

cmd/skaffold/app/cmd/runner.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ package cmd
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"os"
2324

24-
"github.com/pkg/errors"
2525
"github.com/sirupsen/logrus"
2626

2727
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
@@ -42,7 +42,7 @@ var createRunner = createNewRunner
4242
func withRunner(ctx context.Context, action func(runner.Runner, *latest.SkaffoldConfig) error) error {
4343
runner, config, err := createRunner(opts)
4444
if err != nil {
45-
return errors.Wrap(err, "creating runner")
45+
return fmt.Errorf("creating runner: %w", err)
4646
}
4747

4848
err = action(runner, config)
@@ -54,41 +54,41 @@ func withRunner(ctx context.Context, action func(runner.Runner, *latest.Skaffold
5454
func createNewRunner(opts config.SkaffoldOptions) (runner.Runner, *latest.SkaffoldConfig, error) {
5555
parsed, err := schema.ParseConfig(opts.ConfigurationFile, true)
5656
if err != nil {
57-
if os.IsNotExist(errors.Cause(err)) {
57+
if os.IsNotExist(errors.Unwrap(err)) {
5858
return nil, nil, fmt.Errorf("[%s] not found. You might need to run `skaffold init`", opts.ConfigurationFile)
5959
}
6060

6161
// If the error is NOT that the file doesn't exist, then we warn the user
6262
// that maybe they are using an outdated version of Skaffold that's unable to read
6363
// the configuration.
6464
warnIfUpdateIsAvailable()
65-
return nil, nil, errors.Wrap(err, "parsing skaffold config")
65+
return nil, nil, fmt.Errorf("parsing skaffold config: %w", err)
6666
}
6767

6868
config := parsed.(*latest.SkaffoldConfig)
6969

7070
if err = schema.ApplyProfiles(config, opts); err != nil {
71-
return nil, nil, errors.Wrap(err, "applying profiles")
71+
return nil, nil, fmt.Errorf("applying profiles: %w", err)
7272
}
7373

7474
kubectx.ConfigureKubeConfig(opts.KubeConfig, opts.KubeContext, config.Deploy.KubeContext)
7575

7676
if err := defaults.Set(config); err != nil {
77-
return nil, nil, errors.Wrap(err, "setting default values")
77+
return nil, nil, fmt.Errorf("setting default values: %w", err)
7878
}
7979

8080
if err := validation.Process(config); err != nil {
81-
return nil, nil, errors.Wrap(err, "invalid skaffold config")
81+
return nil, nil, fmt.Errorf("invalid skaffold config: %w", err)
8282
}
8383

8484
runCtx, err := runcontext.GetRunContext(opts, config.Pipeline)
8585
if err != nil {
86-
return nil, nil, errors.Wrap(err, "getting run context")
86+
return nil, nil, fmt.Errorf("getting run context: %w", err)
8787
}
8888

8989
runner, err := runner.NewForConfig(runCtx)
9090
if err != nil {
91-
return nil, nil, errors.Wrap(err, "creating runner")
91+
return nil, nil, fmt.Errorf("creating runner: %w", err)
9292
}
9393

9494
return runner, config, nil

0 commit comments

Comments
 (0)