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

Signed-off-by: ChengenH <hce19970702@gmail.com>
This commit is contained in:
ChengenH
2024-04-21 21:49:31 +08:00
parent 8936631603
commit 4a31bd606d
9 changed files with 22 additions and 16 deletions

View File

@@ -17,6 +17,7 @@
package images
import (
"errors"
"fmt"
"io"
"os"
@@ -211,7 +212,7 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
}
if context.Bool("skip-digest-for-named") {
if !context.Bool("digests") {
return fmt.Errorf("--skip-digest-for-named must be specified with --digests option")
return errors.New("--skip-digest-for-named must be specified with --digests option")
}
opts = append(opts, containerd.WithSkipDigestRef(func(name string) bool { return name != "" }))
}
@@ -237,7 +238,7 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
if context.Bool("discard-unpacked-layers") {
if context.Bool("no-unpack") {
return fmt.Errorf("--discard-unpacked-layers and --no-unpack are incompatible options")
return errors.New("--discard-unpacked-layers and --no-unpack are incompatible options")
}
opts = append(opts, containerd.WithDiscardUnpackedLayers())
}

View File

@@ -17,6 +17,7 @@
package images
import (
"errors"
"fmt"
"time"
@@ -56,10 +57,10 @@ When you are done, use the unmount command.
target = context.Args().Get(1)
)
if ref == "" {
return fmt.Errorf("please provide an image reference to mount")
return errors.New("please provide an image reference to mount")
}
if target == "" {
return fmt.Errorf("please provide a target path to mount to")
return errors.New("please provide a target path to mount to")
}
client, ctx, cancel, err := commands.NewClient(context)

View File

@@ -18,6 +18,7 @@ package images
import (
"context"
"errors"
"fmt"
"io"
"os"
@@ -89,7 +90,7 @@ command. As part of this process, we do the following:
ref = context.Args().First()
)
if ref == "" {
return fmt.Errorf("please provide an image reference to pull")
return errors.New("please provide an image reference to pull")
}
client, ctx, cancel, err := commands.NewClient(context)

View File

@@ -17,6 +17,7 @@
package images
import (
"errors"
"fmt"
"github.com/urfave/cli/v2"
@@ -51,10 +52,10 @@ var tagCommand = &cli.Command{
ref = context.Args().First()
)
if ref == "" {
return fmt.Errorf("please provide an image reference to tag from")
return errors.New("please provide an image reference to tag from")
}
if context.NArg() <= 1 {
return fmt.Errorf("please provide an image reference to tag to")
return errors.New("please provide an image reference to tag to")
}
client, ctx, cancel, err := commands.NewClient(context)

View File

@@ -17,6 +17,7 @@
package images
import (
"errors"
"fmt"
"github.com/containerd/containerd/v2/cmd/ctr/commands"
@@ -42,7 +43,7 @@ var unmountCommand = &cli.Command{
target = context.Args().First()
)
if target == "" {
return fmt.Errorf("please provide a target path to unmount from")
return errors.New("please provide a target path to unmount from")
}
client, ctx, cancel, err := commands.NewClient(context)

View File

@@ -17,6 +17,7 @@
package images
import (
"errors"
"fmt"
"os"
"text/tabwriter"
@@ -38,7 +39,7 @@ var usageCommand = &cli.Command{
Action: func(context *cli.Context) error {
var ref = context.Args().First()
if ref == "" {
return fmt.Errorf("please provide an image reference to mount")
return errors.New("please provide an image reference to mount")
}
client, ctx, cancel, err := commands.NewClient(context)