Skip to content
Merged
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 cli/command/container/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package container

import (
"context"
"errors"
"fmt"
"io"

Expand All @@ -12,7 +13,6 @@ import (
"github.com/docker/cli/opts"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/client"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down
5 changes: 3 additions & 2 deletions cli/command/container/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package container

import (
"context"
"errors"
"fmt"
"io"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/moby/sys/atomicwriter"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -53,7 +54,7 @@ func runExport(ctx context.Context, dockerCLI command.Cli, opts exportOptions) e
} else {
writer, err := atomicwriter.New(opts.output, 0o600)
if err != nil {
return errors.Wrap(err, "failed to export container")
return fmt.Errorf("failed to export container: %w", err)
}
defer writer.Close()
output = writer
Expand Down
6 changes: 3 additions & 3 deletions cli/command/container/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package container

import (
"context"
"fmt"
"io"

"github.com/docker/cli/cli"
Expand All @@ -11,7 +12,6 @@ import (
"github.com/docker/cli/opts"
"github.com/docker/cli/templates"
"github.com/moby/moby/client"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -84,15 +84,15 @@ func buildContainerListOptions(options *psOptions) (*client.ContainerListOptions
if len(options.format) > 0 {
tmpl, err := templates.Parse(options.format)
if err != nil {
return nil, errors.Wrap(err, "failed to parse template")
return nil, fmt.Errorf("failed to parse template: %w", err)
}

optionsProcessor := formatter.NewContainerContext()

// This shouldn't error out but swallowing the error makes it harder
// to track down if preProcessor issues come up.
if err := tmpl.Execute(io.Discard, optionsProcessor); err != nil {
return nil, errors.Wrap(err, "failed to execute template")
return nil, fmt.Errorf("failed to execute template: %w", err)
}

// if `size` was not explicitly set to false (with `--size=false`)
Expand Down
62 changes: 31 additions & 31 deletions cli/command/container/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package container
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"os"
"path"
Expand All @@ -19,7 +20,6 @@ import (
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/mount"
"github.com/moby/moby/api/types/network"
"github.com/pkg/errors"
"github.com/spf13/pflag"
cdi "tags.cncf.io/container-device-interface/pkg/parser"
)
Expand Down Expand Up @@ -351,7 +351,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
// Validate the input mac address
if copts.macAddress != "" {
if _, err := opts.ValidateMACAddress(copts.macAddress); err != nil {
return nil, errors.Errorf("%s is not a valid mac address", copts.macAddress)
return nil, fmt.Errorf("%s is not a valid mac address", copts.macAddress)
}
}
if copts.stdin {
Expand All @@ -367,7 +367,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con

swappiness := copts.swappiness
if swappiness != -1 && (swappiness < 0 || swappiness > 100) {
return nil, errors.Errorf("invalid value: %d. Valid memory swappiness range is 0-100", swappiness)
return nil, fmt.Errorf("invalid value: %d. Valid memory swappiness range is 0-100", swappiness)
}

var binds []string
Expand Down Expand Up @@ -442,7 +442,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
// Merge in exposed ports to the map of published ports
for _, e := range copts.expose.GetSlice() {
if strings.Contains(e, ":") {
return nil, errors.Errorf("invalid port format for --expose: %s", e)
return nil, fmt.Errorf("invalid port format for --expose: %s", e)
}
// support two formats for expose, original format <portnum>/[<proto>]
// or <startport-endport>/[<proto>]
Expand All @@ -451,7 +451,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
// if expose a port, the start and end port are the same
start, end, err := nat.ParsePortRange(port)
if err != nil {
return nil, errors.Errorf("invalid range format for --expose: %s, error: %s", e, err)
return nil, fmt.Errorf("invalid range format for --expose: %s, error: %w", e, err)
}
for i := start; i <= end; i++ {
p, err := nat.NewPort(proto, strconv.FormatUint(i, 10))
Expand Down Expand Up @@ -505,22 +505,22 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con

pidMode := container.PidMode(copts.pidMode)
if !pidMode.Valid() {
return nil, errors.Errorf("--pid: invalid PID mode")
return nil, errors.New("--pid: invalid PID mode")
}

utsMode := container.UTSMode(copts.utsMode)
if !utsMode.Valid() {
return nil, errors.Errorf("--uts: invalid UTS mode")
return nil, errors.New("--uts: invalid UTS mode")
}

usernsMode := container.UsernsMode(copts.usernsMode)
if !usernsMode.Valid() {
return nil, errors.Errorf("--userns: invalid USER mode")
return nil, errors.New("--userns: invalid USER mode")
}

cgroupnsMode := container.CgroupnsMode(copts.cgroupnsMode)
if !cgroupnsMode.Valid() {
return nil, errors.Errorf("--cgroupns: invalid CGROUP mode")
return nil, errors.New("--cgroupns: invalid CGROUP mode")
}

restartPolicy, err := opts.ParseRestartPolicy(copts.restartPolicy)
Expand Down Expand Up @@ -555,7 +555,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
copts.healthStartInterval != 0
if copts.noHealthcheck {
if haveHealthSettings {
return nil, errors.Errorf("--no-healthcheck conflicts with --health-* options")
return nil, errors.New("--no-healthcheck conflicts with --health-* options")
}
healthConfig = &container.HealthConfig{Test: []string{"NONE"}}
} else if haveHealthSettings {
Expand All @@ -564,13 +564,13 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
probe = []string{"CMD-SHELL", copts.healthCmd}
}
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, errors.New("--health-start-period cannot be negative")
Expand Down Expand Up @@ -703,7 +703,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
}

if copts.autoRemove && !hostConfig.RestartPolicy.IsNone() {
return nil, errors.Errorf("conflicting options: cannot specify both --restart and --rm")
return nil, errors.New("conflicting options: cannot specify both --restart and --rm")
}

// only set this value if the user provided the flag, else it should default to nil
Expand Down Expand Up @@ -786,7 +786,7 @@ func parseNetworkOpts(copts *containerOptions) (map[string]*network.EndpointSett
return nil, err
}
if _, ok := endpoints[n.Target]; ok {
return nil, invalidParameter(errors.Errorf("network %q is specified multiple times", n.Target))
return nil, invalidParameter(fmt.Errorf("network %q is specified multiple times", n.Target))
}

// For backward compatibility: if no custom options are provided for the network,
Expand Down Expand Up @@ -884,7 +884,7 @@ func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*network.Endpoint
}
if ep.MacAddress != "" {
if _, err := opts.ValidateMACAddress(ep.MacAddress); err != nil {
return nil, errors.Errorf("%s is not a valid mac address", ep.MacAddress)
return nil, fmt.Errorf("%s is not a valid mac address", ep.MacAddress)
}
epConfig.MacAddress = ep.MacAddress
}
Expand All @@ -899,7 +899,7 @@ func convertToStandardNotation(ports []string) ([]string, error) {
for _, param := range strings.Split(publish, ",") {
k, v, ok := strings.Cut(param, "=")
if !ok || k == "" {
return optsList, errors.Errorf("invalid publish opts format (should be name=value but got '%s')", param)
return optsList, fmt.Errorf("invalid publish opts format (should be name=value but got '%s')", param)
}
params[k] = v
}
Expand All @@ -914,7 +914,7 @@ func convertToStandardNotation(ports []string) ([]string, error) {
func parseLoggingOpts(loggingDriver string, loggingOpts []string) (map[string]string, error) {
loggingOptsMap := opts.ConvertKVStringsToMap(loggingOpts)
if loggingDriver == "none" && len(loggingOpts) > 0 {
return map[string]string{}, errors.Errorf("invalid logging opts for driver %s", loggingDriver)
return map[string]string{}, fmt.Errorf("invalid logging opts for driver %s", loggingDriver)
}
return loggingOptsMap, nil
}
Expand All @@ -928,7 +928,7 @@ func parseSecurityOpts(securityOpts []string) ([]string, error) {
}
if (!ok || v == "") && k != "no-new-privileges" {
// "no-new-privileges" is the only option that does not require a value.
return securityOpts, errors.Errorf("Invalid --security-opt: %q", opt)
return securityOpts, fmt.Errorf("invalid --security-opt: %q", opt)
}
if k == "seccomp" {
switch v {
Expand All @@ -939,11 +939,11 @@ func parseSecurityOpts(securityOpts []string) ([]string, error) {
// content if it's valid JSON.
f, err := os.ReadFile(v)
if err != nil {
return securityOpts, errors.Errorf("opening seccomp profile (%s) failed: %v", v, err)
return securityOpts, fmt.Errorf("opening seccomp profile (%s) failed: %w", v, err)
}
b := bytes.NewBuffer(nil)
if err := json.Compact(b, f); err != nil {
return securityOpts, errors.Errorf("compacting json for seccomp profile (%s) failed: %v", v, err)
return securityOpts, fmt.Errorf("compacting json for seccomp profile (%s) failed: %w", v, err)
}
securityOpts[key] = fmt.Sprintf("seccomp=%s", b.Bytes())
}
Expand Down Expand Up @@ -978,7 +978,7 @@ func parseStorageOpts(storageOpts []string) (map[string]string, error) {
for _, option := range storageOpts {
k, v, ok := strings.Cut(option, "=")
if !ok {
return nil, errors.Errorf("invalid storage option")
return nil, errors.New("invalid storage option")
}
m[k] = v
}
Expand All @@ -993,7 +993,7 @@ func parseDevice(device, serverOS string) (container.DeviceMapping, error) {
case "windows":
return parseWindowsDevice(device)
}
return container.DeviceMapping{}, errors.Errorf("unknown server OS: %s", serverOS)
return container.DeviceMapping{}, fmt.Errorf("unknown server OS: %s", serverOS)
}

// parseLinuxDevice parses a device mapping string to a container.DeviceMapping struct
Expand All @@ -1017,7 +1017,7 @@ func parseLinuxDevice(device string) (container.DeviceMapping, error) {
case 1:
src = arr[0]
default:
return container.DeviceMapping{}, errors.Errorf("invalid device specification: %s", device)
return container.DeviceMapping{}, fmt.Errorf("invalid device specification: %s", device)
}

if dst == "" {
Expand Down Expand Up @@ -1047,7 +1047,7 @@ func validateDeviceCgroupRule(val string) (string, error) {
return val, nil
}

return val, errors.Errorf("invalid device cgroup format '%s'", val)
return val, fmt.Errorf("invalid device cgroup format '%s'", val)
}

// validDeviceMode checks if the mode for device is valid or not.
Expand Down Expand Up @@ -1079,7 +1079,7 @@ func validateDevice(val string, serverOS string) (string, error) {
// Windows does validation entirely server-side
return val, nil
}
return "", errors.Errorf("unknown server OS: %s", serverOS)
return "", fmt.Errorf("unknown server OS: %s", serverOS)
}

// validateLinuxPath is the implementation of validateDevice knowing that the
Expand All @@ -1094,12 +1094,12 @@ func validateLinuxPath(val string, validator func(string) bool) (string, error)
var mode string

if strings.Count(val, ":") > 2 {
return val, errors.Errorf("bad format for path: %s", val)
return val, fmt.Errorf("bad format for path: %s", val)
}

split := strings.SplitN(val, ":", 3)
if split[0] == "" {
return val, errors.Errorf("bad format for path: %s", val)
return val, fmt.Errorf("bad format for path: %s", val)
}
switch len(split) {
case 1:
Expand All @@ -1118,13 +1118,13 @@ func validateLinuxPath(val string, validator func(string) bool) (string, error)
containerPath = split[1]
mode = split[2]
if isValid := validator(split[2]); !isValid {
return val, errors.Errorf("bad mode specified: %s", mode)
return val, fmt.Errorf("bad mode specified: %s", mode)
}
val = fmt.Sprintf("%s:%s:%s", split[0], containerPath, mode)
}

if !path.IsAbs(containerPath) {
return val, errors.Errorf("%s is not an absolute path", containerPath)
return val, fmt.Errorf("%s is not an absolute path", containerPath)
}
return val, nil
}
Expand All @@ -1137,5 +1137,5 @@ func validateAttach(val string) (string, error) {
return s, nil
}
}
return val, errors.Errorf("valid streams are STDIN, STDOUT and STDERR")
return val, errors.New("valid streams are STDIN, STDOUT and STDERR")
}
5 changes: 2 additions & 3 deletions cli/command/container/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/docker/cli/cli/command/completion"
"github.com/fvbommel/sortorder"
"github.com/moby/moby/api/types/container"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -66,11 +65,11 @@ func runPort(ctx context.Context, dockerCli command.Cli, opts *portOptions) erro
proto = "tcp"
}
if _, err = strconv.ParseUint(port, 10, 16); err != nil {
return errors.Wrapf(err, "Error: invalid port (%s)", port)
return fmt.Errorf("invalid port (%s): %w", port, err)
}
frontends, exists := c.NetworkSettings.Ports[container.PortRangeProto(port+"/"+proto)]
if !exists || len(frontends) == 0 {
return errors.Errorf("Error: No public port '%s' published for %s", opts.port, opts.container)
return fmt.Errorf("no public port '%s' published for %s", opts.port, opts.container)
}
for _, frontend := range frontends {
out = append(out, net.JoinHostPort(frontend.HostIP, frontend.HostPort))
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package container

import (
"context"
"errors"
"fmt"

"github.com/docker/cli/cli"
Expand All @@ -10,7 +11,6 @@ import (
"github.com/docker/cli/internal/prompt"
"github.com/docker/cli/opts"
"github.com/docker/go-units"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down
Loading
Loading