Skip to content

Commit 7020acb

Browse files
authored
Merge pull request containerd#10100 from ChengenH/main
chore: use errors.New to replace fmt.Errorf with no parameters will much better
2 parents f9b1706 + 4a31bd6 commit 7020acb

File tree

9 files changed

+22
-16
lines changed

9 files changed

+22
-16
lines changed

cmd/ctr/commands/content/content.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ var (
581581
func edit(context *cli.Context, rd io.Reader) (_ io.ReadCloser, retErr error) {
582582
editor := context.String("editor")
583583
if editor == "" {
584-
return nil, fmt.Errorf("editor is required")
584+
return nil, errors.New("editor is required")
585585
}
586586

587587
tmp, err := os.CreateTemp(os.Getenv("XDG_RUNTIME_DIR"), "edit-")

cmd/ctr/commands/images/import.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package images
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"io"
2223
"os"
@@ -211,7 +212,7 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
211212
}
212213
if context.Bool("skip-digest-for-named") {
213214
if !context.Bool("digests") {
214-
return fmt.Errorf("--skip-digest-for-named must be specified with --digests option")
215+
return errors.New("--skip-digest-for-named must be specified with --digests option")
215216
}
216217
opts = append(opts, containerd.WithSkipDigestRef(func(name string) bool { return name != "" }))
217218
}
@@ -237,7 +238,7 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
237238

238239
if context.Bool("discard-unpacked-layers") {
239240
if context.Bool("no-unpack") {
240-
return fmt.Errorf("--discard-unpacked-layers and --no-unpack are incompatible options")
241+
return errors.New("--discard-unpacked-layers and --no-unpack are incompatible options")
241242
}
242243
opts = append(opts, containerd.WithDiscardUnpackedLayers())
243244
}

cmd/ctr/commands/images/mount.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package images
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"time"
2223

@@ -56,10 +57,10 @@ When you are done, use the unmount command.
5657
target = context.Args().Get(1)
5758
)
5859
if ref == "" {
59-
return fmt.Errorf("please provide an image reference to mount")
60+
return errors.New("please provide an image reference to mount")
6061
}
6162
if target == "" {
62-
return fmt.Errorf("please provide a target path to mount to")
63+
return errors.New("please provide a target path to mount to")
6364
}
6465

6566
client, ctx, cancel, err := commands.NewClient(context)

cmd/ctr/commands/images/pull.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package images
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"io"
2324
"os"
@@ -89,7 +90,7 @@ command. As part of this process, we do the following:
8990
ref = context.Args().First()
9091
)
9192
if ref == "" {
92-
return fmt.Errorf("please provide an image reference to pull")
93+
return errors.New("please provide an image reference to pull")
9394
}
9495

9596
client, ctx, cancel, err := commands.NewClient(context)

cmd/ctr/commands/images/tag.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package images
1818

1919
import (
20+
"errors"
2021
"fmt"
2122

2223
"github.com/urfave/cli/v2"
@@ -51,10 +52,10 @@ var tagCommand = &cli.Command{
5152
ref = context.Args().First()
5253
)
5354
if ref == "" {
54-
return fmt.Errorf("please provide an image reference to tag from")
55+
return errors.New("please provide an image reference to tag from")
5556
}
5657
if context.NArg() <= 1 {
57-
return fmt.Errorf("please provide an image reference to tag to")
58+
return errors.New("please provide an image reference to tag to")
5859
}
5960

6061
client, ctx, cancel, err := commands.NewClient(context)

cmd/ctr/commands/images/unmount.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package images
1818

1919
import (
20+
"errors"
2021
"fmt"
2122

2223
"github.com/containerd/containerd/v2/cmd/ctr/commands"
@@ -42,7 +43,7 @@ var unmountCommand = &cli.Command{
4243
target = context.Args().First()
4344
)
4445
if target == "" {
45-
return fmt.Errorf("please provide a target path to unmount from")
46+
return errors.New("please provide a target path to unmount from")
4647
}
4748

4849
client, ctx, cancel, err := commands.NewClient(context)

cmd/ctr/commands/images/usage.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package images
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"os"
2223
"text/tabwriter"
@@ -38,7 +39,7 @@ var usageCommand = &cli.Command{
3839
Action: func(context *cli.Context) error {
3940
var ref = context.Args().First()
4041
if ref == "" {
41-
return fmt.Errorf("please provide an image reference to mount")
42+
return errors.New("please provide an image reference to mount")
4243
}
4344

4445
client, ctx, cancel, err := commands.NewClient(context)

cmd/ctr/commands/run/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func parseMountFlag(m string) (specs.Mount, error) {
6868
for _, field := range fields {
6969
key, val, ok := strings.Cut(field, "=")
7070
if !ok {
71-
return mount, fmt.Errorf("invalid mount specification: expected key=val")
71+
return mount, errors.New("invalid mount specification: expected key=val")
7272
}
7373

7474
switch key {

cmd/ctr/commands/run/run_unix.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
210210
privileged := context.Bool("privileged")
211211
privilegedWithoutHostDevices := context.Bool("privileged-without-host-devices")
212212
if privilegedWithoutHostDevices && !privileged {
213-
return nil, fmt.Errorf("can't use 'privileged-without-host-devices' without 'privileged' specified")
213+
return nil, errors.New("can't use 'privileged-without-host-devices' without 'privileged' specified")
214214
}
215215
if privileged {
216216
if privilegedWithoutHostDevices {
@@ -243,7 +243,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
243243
if caps := context.StringSlice("cap-add"); len(caps) > 0 {
244244
for _, cap := range caps {
245245
if !strings.HasPrefix(cap, "CAP_") {
246-
return nil, fmt.Errorf("capabilities must be specified with 'CAP_' prefix")
246+
return nil, errors.New("capabilities must be specified with 'CAP_' prefix")
247247
}
248248
}
249249
opts = append(opts, oci.WithAddedCapabilities(caps))
@@ -252,7 +252,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
252252
if caps := context.StringSlice("cap-drop"); len(caps) > 0 {
253253
for _, cap := range caps {
254254
if !strings.HasPrefix(cap, "CAP_") {
255-
return nil, fmt.Errorf("capabilities must be specified with 'CAP_' prefix")
255+
return nil, errors.New("capabilities must be specified with 'CAP_' prefix")
256256
}
257257
}
258258
opts = append(opts, oci.WithDroppedCapabilities(caps))
@@ -261,7 +261,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
261261
seccompProfile := context.String("seccomp-profile")
262262

263263
if !context.Bool("seccomp") && seccompProfile != "" {
264-
return nil, fmt.Errorf("seccomp must be set to true, if using a custom seccomp-profile")
264+
return nil, errors.New("seccomp must be set to true, if using a custom seccomp-profile")
265265
}
266266

267267
if context.Bool("seccomp") {
@@ -278,7 +278,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
278278

279279
if s := context.String("apparmor-profile"); len(s) > 0 {
280280
if len(context.String("apparmor-default-profile")) > 0 {
281-
return nil, fmt.Errorf("apparmor-profile conflicts with apparmor-default-profile")
281+
return nil, errors.New("apparmor-profile conflicts with apparmor-default-profile")
282282
}
283283
opts = append(opts, apparmor.WithProfile(s))
284284
}

0 commit comments

Comments
 (0)