diff options
author | openshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com> | 2022-07-08 09:24:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-08 09:24:25 +0000 |
commit | 6087fb2116aaeae995e8423872ffe637e8be128f (patch) | |
tree | e8bd00a9b325a51a49de02e868f06eec2deeb529 /pkg/domain | |
parent | a2bcf833c98cb38eb28dc65a8768963d0b7344fc (diff) | |
parent | a46f798831df06c472b288db7b34de8536a7ea5a (diff) | |
download | podman-6087fb2116aaeae995e8423872ffe637e8be128f.tar.gz podman-6087fb2116aaeae995e8423872ffe637e8be128f.tar.bz2 podman-6087fb2116aaeae995e8423872ffe637e8be128f.zip |
Merge pull request #14839 from saschagrunert/errors-pkg
pkg: switch to golang native error wrapping
Diffstat (limited to 'pkg/domain')
-rw-r--r-- | pkg/domain/entities/container_ps.go | 4 | ||||
-rw-r--r-- | pkg/domain/filters/pods.go | 9 | ||||
-rw-r--r-- | pkg/domain/filters/volumes.go | 8 | ||||
-rw-r--r-- | pkg/domain/infra/abi/generate.go | 9 | ||||
-rw-r--r-- | pkg/domain/infra/abi/images_list.go | 14 | ||||
-rw-r--r-- | pkg/domain/infra/abi/parse/parse.go | 18 | ||||
-rw-r--r-- | pkg/domain/infra/abi/pods_stats.go | 4 | ||||
-rw-r--r-- | pkg/domain/infra/abi/terminal/terminal.go | 4 | ||||
-rw-r--r-- | pkg/domain/infra/abi/terminal/terminal_linux.go | 3 | ||||
-rw-r--r-- | pkg/domain/infra/abi/trust.go | 15 | ||||
-rw-r--r-- | pkg/domain/infra/runtime_libpod.go | 4 | ||||
-rw-r--r-- | pkg/domain/infra/tunnel/auto-update.go | 2 | ||||
-rw-r--r-- | pkg/domain/infra/tunnel/events.go | 7 | ||||
-rw-r--r-- | pkg/domain/infra/tunnel/helpers.go | 9 | ||||
-rw-r--r-- | pkg/domain/infra/tunnel/images.go | 16 | ||||
-rw-r--r-- | pkg/domain/infra/tunnel/manifest.go | 14 | ||||
-rw-r--r-- | pkg/domain/infra/tunnel/network.go | 5 | ||||
-rw-r--r-- | pkg/domain/infra/tunnel/secrets.go | 6 | ||||
-rw-r--r-- | pkg/domain/infra/tunnel/volumes.go | 5 | ||||
-rw-r--r-- | pkg/domain/utils/scp.go | 31 | ||||
-rw-r--r-- | pkg/domain/utils/secrets_filters.go | 4 |
21 files changed, 96 insertions, 95 deletions
diff --git a/pkg/domain/entities/container_ps.go b/pkg/domain/entities/container_ps.go index a5562e7c9..519d2b7da 100644 --- a/pkg/domain/entities/container_ps.go +++ b/pkg/domain/entities/container_ps.go @@ -1,13 +1,13 @@ package entities import ( + "errors" "sort" "strings" "time" "github.com/containers/common/libnetwork/types" "github.com/containers/podman/v4/pkg/ps/define" - "github.com/pkg/errors" ) // ListContainer describes a container suitable for listing @@ -166,7 +166,7 @@ func SortPsOutput(sortBy string, psOutput SortListContainers) (SortListContainer case "pod": sort.Sort(psSortedPod{psOutput}) default: - return nil, errors.Errorf("invalid option for --sort, options are: command, created, id, image, names, runningfor, size, or status") + return nil, errors.New("invalid option for --sort, options are: command, created, id, image, names, runningfor, size, or status") } return psOutput, nil } diff --git a/pkg/domain/filters/pods.go b/pkg/domain/filters/pods.go index c2ed359f5..78b97db64 100644 --- a/pkg/domain/filters/pods.go +++ b/pkg/domain/filters/pods.go @@ -1,6 +1,8 @@ package filters import ( + "errors" + "fmt" "strconv" "strings" @@ -8,7 +10,6 @@ import ( "github.com/containers/podman/v4/libpod" "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/pkg/util" - "github.com/pkg/errors" ) // GeneratePodFilterFunc takes a filter and filtervalue (key, value) @@ -59,7 +60,7 @@ func GeneratePodFilterFunc(filter string, filterValues []string, r *libpod.Runti case "ctr-status": for _, filterValue := range filterValues { if !cutil.StringInSlice(filterValue, []string{"created", "running", "paused", "stopped", "exited", "unknown"}) { - return nil, errors.Errorf("%s is not a valid status", filterValue) + return nil, fmt.Errorf("%s is not a valid status", filterValue) } } return func(p *libpod.Pod) bool { @@ -96,7 +97,7 @@ func GeneratePodFilterFunc(filter string, filterValues []string, r *libpod.Runti case "status": for _, filterValue := range filterValues { if !cutil.StringInSlice(filterValue, []string{"stopped", "running", "paused", "exited", "dead", "created", "degraded"}) { - return nil, errors.Errorf("%s is not a valid pod status", filterValue) + return nil, fmt.Errorf("%s is not a valid pod status", filterValue) } } return func(p *libpod.Pod) bool { @@ -158,5 +159,5 @@ func GeneratePodFilterFunc(filter string, filterValues []string, r *libpod.Runti return false }, nil } - return nil, errors.Errorf("%s is an invalid filter", filter) + return nil, fmt.Errorf("%s is an invalid filter", filter) } diff --git a/pkg/domain/filters/volumes.go b/pkg/domain/filters/volumes.go index a18e6332c..7c5047225 100644 --- a/pkg/domain/filters/volumes.go +++ b/pkg/domain/filters/volumes.go @@ -1,13 +1,13 @@ package filters import ( + "fmt" "net/url" "regexp" "strings" "github.com/containers/podman/v4/libpod" "github.com/containers/podman/v4/pkg/util" - "github.com/pkg/errors" ) func GenerateVolumeFilters(filters url.Values) ([]libpod.VolumeFilter, error) { @@ -72,7 +72,7 @@ func GenerateVolumeFilters(filters url.Values) ([]libpod.VolumeFilter, error) { // invert the result of IsDangling. invert = true default: - return nil, errors.Errorf("%q is not a valid value for the \"dangling\" filter - must be true or false", danglingVal) + return nil, fmt.Errorf("%q is not a valid value for the \"dangling\" filter - must be true or false", danglingVal) } vf = append(vf, func(v *libpod.Volume) bool { dangling, err := v.IsDangling() @@ -85,7 +85,7 @@ func GenerateVolumeFilters(filters url.Values) ([]libpod.VolumeFilter, error) { return dangling }) default: - return nil, errors.Errorf("%q is an invalid volume filter", filter) + return nil, fmt.Errorf("%q is an invalid volume filter", filter) } } } @@ -109,7 +109,7 @@ func GeneratePruneVolumeFilters(filters url.Values) ([]libpod.VolumeFilter, erro } vf = append(vf, f) default: - return nil, errors.Errorf("%q is an invalid volume filter", filter) + return nil, fmt.Errorf("%q is an invalid volume filter", filter) } } } diff --git a/pkg/domain/infra/abi/generate.go b/pkg/domain/infra/abi/generate.go index ff85dee9b..5c1047b74 100644 --- a/pkg/domain/infra/abi/generate.go +++ b/pkg/domain/infra/abi/generate.go @@ -12,7 +12,6 @@ import ( k8sAPI "github.com/containers/podman/v4/pkg/k8s.io/api/core/v1" "github.com/containers/podman/v4/pkg/systemd/generate" "github.com/ghodss/yaml" - "github.com/pkg/errors" ) func (ic *ContainerEngine) GenerateSystemd(ctx context.Context, nameOrID string, options entities.GenerateSystemdOptions) (*entities.GenerateSystemdReport, error) { @@ -30,8 +29,8 @@ func (ic *ContainerEngine) GenerateSystemd(ctx context.Context, nameOrID string, // If it's not a container, we either have a pod or garbage. pod, err := ic.Libpod.LookupPod(nameOrID) if err != nil { - err = errors.Wrap(ctrErr, err.Error()) - return nil, errors.Wrapf(err, "%s does not refer to a container or pod", nameOrID) + err = fmt.Errorf("%v: %w", err.Error(), ctrErr) + return nil, fmt.Errorf("%s does not refer to a container or pod: %w", nameOrID, err) } // Generate the units for the pod and all its containers. @@ -63,7 +62,7 @@ func (ic *ContainerEngine) GenerateKube(ctx context.Context, nameOrIDs []string, // now that infra holds NS data, we need to support dependencies. // we cannot deal with ctrs already in a pod. if len(ctr.PodID()) > 0 { - return nil, errors.Errorf("container %s is associated with pod %s: use generate on the pod itself", ctr.ID(), ctr.PodID()) + return nil, fmt.Errorf("container %s is associated with pod %s: use generate on the pod itself", ctr.ID(), ctr.PodID()) } ctrs = append(ctrs, ctr) continue @@ -92,7 +91,7 @@ func (ic *ContainerEngine) GenerateKube(ctx context.Context, nameOrIDs []string, } // If it reaches here is because the name or id did not exist. - return nil, errors.Errorf("Name or ID %q not found", nameOrID) + return nil, fmt.Errorf("name or ID %q not found", nameOrID) } // Generate kube persistent volume claims from volumes. diff --git a/pkg/domain/infra/abi/images_list.go b/pkg/domain/infra/abi/images_list.go index 8f5591e92..96e99fbf0 100644 --- a/pkg/domain/infra/abi/images_list.go +++ b/pkg/domain/infra/abi/images_list.go @@ -2,10 +2,10 @@ package abi import ( "context" + "fmt" "github.com/containers/common/libimage" "github.com/containers/podman/v4/pkg/domain/entities" - "github.com/pkg/errors" ) func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) ([]*entities.ImageSummary, error) { @@ -28,11 +28,11 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) for _, img := range images { repoDigests, err := img.RepoDigests() if err != nil { - return nil, errors.Wrapf(err, "getting repoDigests from image %q", img.ID()) + return nil, fmt.Errorf("getting repoDigests from image %q: %w", img.ID(), err) } isDangling, err := img.IsDangling(ctx) if err != nil { - return nil, errors.Wrapf(err, "error checking if image %q is dangling", img.ID()) + return nil, fmt.Errorf("error checking if image %q is dangling: %w", img.ID(), err) } e := entities.ImageSummary{ @@ -49,18 +49,18 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) } e.Labels, err = img.Labels(ctx) if err != nil { - return nil, errors.Wrapf(err, "error retrieving label for image %q: you may need to remove the image to resolve the error", img.ID()) + return nil, fmt.Errorf("error retrieving label for image %q: you may need to remove the image to resolve the error: %w", img.ID(), err) } ctnrs, err := img.Containers() if err != nil { - return nil, errors.Wrapf(err, "error retrieving containers for image %q: you may need to remove the image to resolve the error", img.ID()) + return nil, fmt.Errorf("error retrieving containers for image %q: you may need to remove the image to resolve the error: %w", img.ID(), err) } e.Containers = len(ctnrs) sz, err := img.Size() if err != nil { - return nil, errors.Wrapf(err, "error retrieving size of image %q: you may need to remove the image to resolve the error", img.ID()) + return nil, fmt.Errorf("error retrieving size of image %q: you may need to remove the image to resolve the error: %w", img.ID(), err) } e.Size = sz // This is good enough for now, but has to be @@ -69,7 +69,7 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) parent, err := img.Parent(ctx) if err != nil { - return nil, errors.Wrapf(err, "error retrieving parent of image %q: you may need to remove the image to resolve the error", img.ID()) + return nil, fmt.Errorf("error retrieving parent of image %q: you may need to remove the image to resolve the error: %w", img.ID(), err) } if parent != nil { e.ParentId = parent.ID() diff --git a/pkg/domain/infra/abi/parse/parse.go b/pkg/domain/infra/abi/parse/parse.go index 4e8c2e508..19699589b 100644 --- a/pkg/domain/infra/abi/parse/parse.go +++ b/pkg/domain/infra/abi/parse/parse.go @@ -1,13 +1,13 @@ package parse import ( + "fmt" "strconv" "strings" "github.com/containers/podman/v4/libpod" "github.com/containers/podman/v4/libpod/define" units "github.com/docker/go-units" - "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -32,7 +32,7 @@ func VolumeOptions(opts map[string]string) ([]libpod.VolumeCreateOption, error) case "size": size, err := units.FromHumanSize(splitO[1]) if err != nil { - return nil, errors.Wrapf(err, "cannot convert size %s to integer", splitO[1]) + return nil, fmt.Errorf("cannot convert size %s to integer: %w", splitO[1], err) } libpodOptions = append(libpodOptions, libpod.WithVolumeSize(uint64(size))) finalVal = append(finalVal, o) @@ -41,7 +41,7 @@ func VolumeOptions(opts map[string]string) ([]libpod.VolumeCreateOption, error) case "inodes": inodes, err := strconv.ParseUint(splitO[1], 10, 64) if err != nil { - return nil, errors.Wrapf(err, "cannot convert inodes %s to integer", splitO[1]) + return nil, fmt.Errorf("cannot convert inodes %s to integer: %w", splitO[1], err) } libpodOptions = append(libpodOptions, libpod.WithVolumeInodes(inodes)) finalVal = append(finalVal, o) @@ -49,11 +49,11 @@ func VolumeOptions(opts map[string]string) ([]libpod.VolumeCreateOption, error) volumeOptions["INODES"] = splitO[1] case "uid": if len(splitO) != 2 { - return nil, errors.Wrapf(define.ErrInvalidArg, "uid option must provide a UID") + return nil, fmt.Errorf("uid option must provide a UID: %w", define.ErrInvalidArg) } intUID, err := strconv.Atoi(splitO[1]) if err != nil { - return nil, errors.Wrapf(err, "cannot convert UID %s to integer", splitO[1]) + return nil, fmt.Errorf("cannot convert UID %s to integer: %w", splitO[1], err) } logrus.Debugf("Removing uid= from options and adding WithVolumeUID for UID %d", intUID) libpodOptions = append(libpodOptions, libpod.WithVolumeUID(intUID), libpod.WithVolumeNoChown()) @@ -62,11 +62,11 @@ func VolumeOptions(opts map[string]string) ([]libpod.VolumeCreateOption, error) volumeOptions["UID"] = splitO[1] case "gid": if len(splitO) != 2 { - return nil, errors.Wrapf(define.ErrInvalidArg, "gid option must provide a GID") + return nil, fmt.Errorf("gid option must provide a GID: %w", define.ErrInvalidArg) } intGID, err := strconv.Atoi(splitO[1]) if err != nil { - return nil, errors.Wrapf(err, "cannot convert GID %s to integer", splitO[1]) + return nil, fmt.Errorf("cannot convert GID %s to integer: %w", splitO[1], err) } logrus.Debugf("Removing gid= from options and adding WithVolumeGID for GID %d", intGID) libpodOptions = append(libpodOptions, libpod.WithVolumeGID(intGID), libpod.WithVolumeNoChown()) @@ -80,11 +80,11 @@ func VolumeOptions(opts map[string]string) ([]libpod.VolumeCreateOption, error) volumeOptions["NOQUOTA"] = "true" case "timeout": if len(splitO) != 2 { - return nil, errors.Wrapf(define.ErrInvalidArg, "timeout option must provide a valid timeout in seconds") + return nil, fmt.Errorf("timeout option must provide a valid timeout in seconds: %w", define.ErrInvalidArg) } intTimeout, err := strconv.Atoi(splitO[1]) if err != nil { - return nil, errors.Wrapf(err, "cannot convert Timeout %s to an integer", splitO[1]) + return nil, fmt.Errorf("cannot convert Timeout %s to an integer: %w", splitO[1], err) } logrus.Debugf("Removing timeout from options and adding WithTimeout for Timeout %d", intTimeout) libpodOptions = append(libpodOptions, libpod.WithVolumeDriverTimeout(intTimeout)) diff --git a/pkg/domain/infra/abi/pods_stats.go b/pkg/domain/infra/abi/pods_stats.go index 6123027b8..a270db769 100644 --- a/pkg/domain/infra/abi/pods_stats.go +++ b/pkg/domain/infra/abi/pods_stats.go @@ -2,6 +2,7 @@ package abi import ( "context" + "errors" "fmt" "github.com/containers/common/pkg/cgroups" @@ -10,7 +11,6 @@ import ( "github.com/containers/podman/v4/pkg/rootless" "github.com/containers/podman/v4/utils" "github.com/docker/go-units" - "github.com/pkg/errors" ) // PodStats implements printing stats about pods. @@ -28,7 +28,7 @@ func (ic *ContainerEngine) PodStats(ctx context.Context, namesOrIds []string, op // Get the (running) pods and convert them to the entities format. pods, err := getPodsByContext(options.All, options.Latest, namesOrIds, ic.Libpod) if err != nil { - return nil, errors.Wrap(err, "unable to get list of pods") + return nil, fmt.Errorf("unable to get list of pods: %w", err) } return ic.podsToStatsReport(pods) } diff --git a/pkg/domain/infra/abi/terminal/terminal.go b/pkg/domain/infra/abi/terminal/terminal.go index 45ebded26..37dadd92a 100644 --- a/pkg/domain/infra/abi/terminal/terminal.go +++ b/pkg/domain/infra/abi/terminal/terminal.go @@ -2,13 +2,13 @@ package terminal import ( "context" + "fmt" "os" "os/signal" "github.com/containers/common/pkg/resize" lsignal "github.com/containers/podman/v4/pkg/signal" "github.com/moby/term" - "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -89,7 +89,7 @@ func handleTerminalAttach(ctx context.Context, resize chan resize.TerminalSize) if err != nil { // allow caller to not have to do any cleaning up if we error here cancel() - return nil, nil, errors.Wrapf(err, "unable to save terminal state") + return nil, nil, fmt.Errorf("unable to save terminal state: %w", err) } logrus.SetFormatter(&RawTtyFormatter{}) diff --git a/pkg/domain/infra/abi/terminal/terminal_linux.go b/pkg/domain/infra/abi/terminal/terminal_linux.go index e8f338418..222590871 100644 --- a/pkg/domain/infra/abi/terminal/terminal_linux.go +++ b/pkg/domain/infra/abi/terminal/terminal_linux.go @@ -9,7 +9,6 @@ import ( "github.com/containers/common/pkg/resize" "github.com/containers/podman/v4/libpod" "github.com/containers/podman/v4/libpod/define" - "github.com/pkg/errors" "github.com/sirupsen/logrus" "golang.org/x/term" ) @@ -104,7 +103,7 @@ func StartAttachCtr(ctx context.Context, ctr *libpod.Container, stdout, stderr, err = <-attachChan if err != nil { - return errors.Wrapf(err, "error attaching to container %s", ctr.ID()) + return fmt.Errorf("error attaching to container %s: %w", ctr.ID(), err) } return nil diff --git a/pkg/domain/infra/abi/trust.go b/pkg/domain/infra/abi/trust.go index 58f099bb6..0e3d8fad9 100644 --- a/pkg/domain/infra/abi/trust.go +++ b/pkg/domain/infra/abi/trust.go @@ -3,13 +3,14 @@ package abi import ( "context" "encoding/json" + "errors" + "fmt" "io/ioutil" "os" "strings" "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/trust" - "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -35,11 +36,11 @@ func (ir *ImageEngine) ShowTrust(ctx context.Context, args []string, options ent } policyContentStruct, err := trust.GetPolicy(policyPath) if err != nil { - return nil, errors.Wrapf(err, "could not read trust policies") + return nil, fmt.Errorf("could not read trust policies: %w", err) } report.Policies, err = getPolicyShowOutput(policyContentStruct, report.SystemRegistriesDirPath) if err != nil { - return nil, errors.Wrapf(err, "could not show trust policies") + return nil, fmt.Errorf("could not show trust policies: %w", err) } return &report, nil } @@ -56,7 +57,7 @@ func (ir *ImageEngine) SetTrust(ctx context.Context, args []string, options enti pubkeysfile := options.PubKeysFile if len(pubkeysfile) == 0 && trustType == "signedBy" { - return errors.Errorf("At least one public key must be defined for type 'signedBy'") + return errors.New("at least one public key must be defined for type 'signedBy'") } policyPath := trust.DefaultPolicyPath(ir.Libpod.SystemContext()) @@ -70,7 +71,7 @@ func (ir *ImageEngine) SetTrust(ctx context.Context, args []string, options enti return err } if err := json.Unmarshal(policyContent, &policyContentStruct); err != nil { - return errors.Errorf("could not read trust policies") + return errors.New("could not read trust policies") } } if len(pubkeysfile) != 0 { @@ -84,7 +85,7 @@ func (ir *ImageEngine) SetTrust(ctx context.Context, args []string, options enti policyContentStruct.Default = newReposContent } else { if len(policyContentStruct.Default) == 0 { - return errors.Errorf("default trust policy must be set") + return errors.New("default trust policy must be set") } registryExists := false for transport, transportval := range policyContentStruct.Transports { @@ -107,7 +108,7 @@ func (ir *ImageEngine) SetTrust(ctx context.Context, args []string, options enti data, err := json.MarshalIndent(policyContentStruct, "", " ") if err != nil { - return errors.Wrapf(err, "error setting trust policy") + return fmt.Errorf("error setting trust policy: %w", err) } return ioutil.WriteFile(policyPath, data, 0644) } diff --git a/pkg/domain/infra/runtime_libpod.go b/pkg/domain/infra/runtime_libpod.go index 162025969..f76fab4ea 100644 --- a/pkg/domain/infra/runtime_libpod.go +++ b/pkg/domain/infra/runtime_libpod.go @@ -5,6 +5,7 @@ package infra import ( "context" + "errors" "fmt" "os" "os/signal" @@ -18,7 +19,6 @@ import ( "github.com/containers/podman/v4/pkg/rootless" "github.com/containers/storage/pkg/idtools" "github.com/containers/storage/types" - "github.com/pkg/errors" "github.com/sirupsen/logrus" flag "github.com/spf13/pflag" ) @@ -316,7 +316,7 @@ func ParseIDMapping(mode namespaces.UsernsMode, uidMapSlice, gidMapSlice []strin uids, gids, err := rootless.GetConfiguredMappings() if err != nil { - return nil, errors.Wrapf(err, "cannot read mappings") + return nil, fmt.Errorf("cannot read mappings: %w", err) } maxUID, maxGID := 0, 0 for _, u := range uids { diff --git a/pkg/domain/infra/tunnel/auto-update.go b/pkg/domain/infra/tunnel/auto-update.go index ba41f0378..469da5a7a 100644 --- a/pkg/domain/infra/tunnel/auto-update.go +++ b/pkg/domain/infra/tunnel/auto-update.go @@ -2,9 +2,9 @@ package tunnel import ( "context" + "errors" "github.com/containers/podman/v4/pkg/domain/entities" - "github.com/pkg/errors" ) func (ic *ContainerEngine) AutoUpdate(ctx context.Context, options entities.AutoUpdateOptions) ([]*entities.AutoUpdateReport, []error) { diff --git a/pkg/domain/infra/tunnel/events.go b/pkg/domain/infra/tunnel/events.go index b472ad03a..30be92e23 100644 --- a/pkg/domain/infra/tunnel/events.go +++ b/pkg/domain/infra/tunnel/events.go @@ -2,13 +2,12 @@ package tunnel import ( "context" + "fmt" "strings" "github.com/containers/podman/v4/libpod/events" "github.com/containers/podman/v4/pkg/bindings/system" "github.com/containers/podman/v4/pkg/domain/entities" - - "github.com/pkg/errors" ) func (ic *ContainerEngine) Events(ctx context.Context, opts entities.EventsOptions) error { @@ -17,7 +16,7 @@ func (ic *ContainerEngine) Events(ctx context.Context, opts entities.EventsOptio for _, filter := range opts.Filter { split := strings.Split(filter, "=") if len(split) < 2 { - return errors.Errorf("invalid filter %q", filter) + return fmt.Errorf("invalid filter %q", filter) } filters[split[0]] = append(filters[split[0]], strings.Join(split[1:], "=")) } @@ -56,7 +55,7 @@ func (ic *ContainerEngine) GetLastContainerEvent(ctx context.Context, nameOrID s return nil, err } if len(containerEvents) < 1 { - return nil, errors.Wrapf(events.ErrEventNotFound, "%s not found", containerEvent.String()) + return nil, fmt.Errorf("%s not found: %w", containerEvent.String(), events.ErrEventNotFound) } // return the last element in the slice return containerEvents[len(containerEvents)-1], nil diff --git a/pkg/domain/infra/tunnel/helpers.go b/pkg/domain/infra/tunnel/helpers.go index 6c043465c..24b2b619d 100644 --- a/pkg/domain/infra/tunnel/helpers.go +++ b/pkg/domain/infra/tunnel/helpers.go @@ -2,13 +2,14 @@ package tunnel import ( "context" + "errors" + "fmt" "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/pkg/bindings/containers" "github.com/containers/podman/v4/pkg/bindings/pods" "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/errorhandling" - "github.com/pkg/errors" ) // FIXME: the `ignore` parameter is very likely wrong here as it should rather @@ -69,7 +70,7 @@ func getContainersAndInputByContext(contextWithConnection context.Context, all, } if !found && !ignore { - return nil, nil, errors.Wrapf(define.ErrNoSuchCtr, "unable to find container %q", nameOrID) + return nil, nil, fmt.Errorf("unable to find container %q: %w", nameOrID, define.ErrNoSuchCtr) } } return filtered, rawInputs, nil @@ -102,7 +103,7 @@ func getPodsByContext(contextWithConnection context.Context, all bool, namesOrID inspectData, err := pods.Inspect(contextWithConnection, nameOrID, nil) if err != nil { if errorhandling.Contains(err, define.ErrNoSuchPod) { - return nil, errors.Wrapf(define.ErrNoSuchPod, "unable to find pod %q", nameOrID) + return nil, fmt.Errorf("unable to find pod %q: %w", nameOrID, define.ErrNoSuchPod) } return nil, err } @@ -120,7 +121,7 @@ func getPodsByContext(contextWithConnection context.Context, all bool, namesOrID } if !found { - return nil, errors.Wrapf(define.ErrNoSuchPod, "unable to find pod %q", nameOrID) + return nil, fmt.Errorf("unable to find pod %q: %w", nameOrID, define.ErrNoSuchPod) } } return filtered, nil diff --git a/pkg/domain/infra/tunnel/images.go b/pkg/domain/infra/tunnel/images.go index 09f8ac4c3..18f750dcc 100644 --- a/pkg/domain/infra/tunnel/images.go +++ b/pkg/domain/infra/tunnel/images.go @@ -2,6 +2,7 @@ package tunnel import ( "context" + "errors" "fmt" "io/ioutil" "os" @@ -19,7 +20,6 @@ import ( "github.com/containers/podman/v4/pkg/domain/utils" "github.com/containers/podman/v4/pkg/errorhandling" utils2 "github.com/containers/podman/v4/utils" - "github.com/pkg/errors" ) func (ir *ImageEngine) Exists(_ context.Context, nameOrID string) (*entities.BoolReport, error) { @@ -131,7 +131,7 @@ func (ir *ImageEngine) Tag(ctx context.Context, nameOrID string, tags []string, ) ref, err := reference.Parse(newTag) if err != nil { - return errors.Wrapf(err, "error parsing reference %q", newTag) + return fmt.Errorf("error parsing reference %q: %w", newTag, err) } if t, ok := ref.(reference.Tagged); ok { tag = t.Tag() @@ -140,7 +140,7 @@ func (ir *ImageEngine) Tag(ctx context.Context, nameOrID string, tags []string, repo = r.Name() } if len(repo) < 1 { - return errors.Errorf("invalid image name %q", nameOrID) + return fmt.Errorf("invalid image name %q", nameOrID) } if err := images.Tag(ir.ClientCtx, nameOrID, tag, repo, options); err != nil { return err @@ -161,7 +161,7 @@ func (ir *ImageEngine) Untag(ctx context.Context, nameOrID string, tags []string ) ref, err := reference.Parse(newTag) if err != nil { - return errors.Wrapf(err, "error parsing reference %q", newTag) + return fmt.Errorf("error parsing reference %q: %w", newTag, err) } if t, ok := ref.(reference.Tagged); ok { tag = t.Tag() @@ -173,7 +173,7 @@ func (ir *ImageEngine) Untag(ctx context.Context, nameOrID string, tags []string repo = r.Name() } if len(repo) < 1 { - return errors.Errorf("invalid image name %q", nameOrID) + return fmt.Errorf("invalid image name %q", nameOrID) } if err := images.Untag(ir.ClientCtx, nameOrID, tag, repo, options); err != nil { return err @@ -194,7 +194,7 @@ func (ir *ImageEngine) Inspect(ctx context.Context, namesOrIDs []string, opts en return nil, nil, err } if errModel.ResponseCode == 404 { - errs = append(errs, errors.Wrapf(err, "unable to inspect %q", i)) + errs = append(errs, fmt.Errorf("unable to inspect %q: %w", i, err)) continue } return nil, nil, err @@ -215,7 +215,7 @@ func (ir *ImageEngine) Load(ctx context.Context, opts entities.ImageLoadOptions) return nil, err } if fInfo.IsDir() { - return nil, errors.Errorf("remote client supports archives only but %q is a directory", opts.Input) + return nil, fmt.Errorf("remote client supports archives only but %q is a directory", opts.Input) } return images.Load(ir.ClientCtx, f) } @@ -296,7 +296,7 @@ func (ir *ImageEngine) Save(ctx context.Context, nameOrID string, tags []string, switch { case err == nil: if info.Mode().IsRegular() { - return errors.Errorf("%q already exists as a regular file", opts.Output) + return fmt.Errorf("%q already exists as a regular file", opts.Output) } case os.IsNotExist(err): if err := os.Mkdir(opts.Output, 0755); err != nil { diff --git a/pkg/domain/infra/tunnel/manifest.go b/pkg/domain/infra/tunnel/manifest.go index 09c37b896..d2554f198 100644 --- a/pkg/domain/infra/tunnel/manifest.go +++ b/pkg/domain/infra/tunnel/manifest.go @@ -3,6 +3,7 @@ package tunnel import ( "context" "encoding/json" + "errors" "fmt" "strings" @@ -10,7 +11,6 @@ import ( "github.com/containers/podman/v4/pkg/bindings/images" "github.com/containers/podman/v4/pkg/bindings/manifests" "github.com/containers/podman/v4/pkg/domain/entities" - "github.com/pkg/errors" ) // ManifestCreate implements manifest create via ImageEngine @@ -18,7 +18,7 @@ func (ir *ImageEngine) ManifestCreate(ctx context.Context, name string, images [ options := new(manifests.CreateOptions).WithAll(opts.All) imageID, err := manifests.Create(ir.ClientCtx, name, images, options) if err != nil { - return imageID, errors.Wrapf(err, "error creating manifest") + return imageID, fmt.Errorf("error creating manifest: %w", err) } return imageID, err } @@ -36,12 +36,12 @@ func (ir *ImageEngine) ManifestExists(ctx context.Context, name string) (*entiti func (ir *ImageEngine) ManifestInspect(_ context.Context, name string) ([]byte, error) { list, err := manifests.Inspect(ir.ClientCtx, name, nil) if err != nil { - return nil, errors.Wrapf(err, "error getting content of manifest list or image %s", name) + return nil, fmt.Errorf("error getting content of manifest list or image %s: %w", name, err) } buf, err := json.MarshalIndent(list, "", " ") if err != nil { - return buf, errors.Wrapf(err, "error rendering manifest for display") + return buf, fmt.Errorf("error rendering manifest for display: %w", err) } return buf, err } @@ -56,7 +56,7 @@ func (ir *ImageEngine) ManifestAdd(_ context.Context, name string, imageNames [] for _, annotationSpec := range opts.Annotation { spec := strings.SplitN(annotationSpec, "=", 2) if len(spec) != 2 { - return "", errors.Errorf("no value given for annotation %q", spec[0]) + return "", fmt.Errorf("no value given for annotation %q", spec[0]) } annotations[spec[0]] = spec[1] } @@ -72,7 +72,7 @@ func (ir *ImageEngine) ManifestAdd(_ context.Context, name string, imageNames [] id, err := manifests.Add(ir.ClientCtx, name, options) if err != nil { - return id, errors.Wrapf(err, "error adding to manifest list %s", name) + return id, fmt.Errorf("error adding to manifest list %s: %w", name, err) } return id, nil } @@ -86,7 +86,7 @@ func (ir *ImageEngine) ManifestAnnotate(ctx context.Context, name, images string func (ir *ImageEngine) ManifestRemoveDigest(ctx context.Context, name string, image string) (string, error) { updatedListID, err := manifests.Remove(ir.ClientCtx, name, image, nil) if err != nil { - return updatedListID, errors.Wrapf(err, "error removing from manifest %s", name) + return updatedListID, fmt.Errorf("error removing from manifest %s: %w", name, err) } return fmt.Sprintf("%s :%s\n", updatedListID, image), nil } diff --git a/pkg/domain/infra/tunnel/network.go b/pkg/domain/infra/tunnel/network.go index 415999a96..ffdcbab1e 100644 --- a/pkg/domain/infra/tunnel/network.go +++ b/pkg/domain/infra/tunnel/network.go @@ -2,13 +2,14 @@ package tunnel import ( "context" + "errors" + "fmt" "github.com/containers/common/libnetwork/types" "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/pkg/bindings/network" "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/errorhandling" - "github.com/pkg/errors" ) func (ic *ContainerEngine) NetworkList(ctx context.Context, opts entities.NetworkListOptions) ([]types.Network, error) { @@ -30,7 +31,7 @@ func (ic *ContainerEngine) NetworkInspect(ctx context.Context, namesOrIds []stri return nil, nil, err } if errModel.ResponseCode == 404 { - errs = append(errs, errors.Wrapf(define.ErrNoSuchNetwork, "network %s", name)) + errs = append(errs, fmt.Errorf("network %s: %w", name, define.ErrNoSuchNetwork)) continue } return nil, nil, err diff --git a/pkg/domain/infra/tunnel/secrets.go b/pkg/domain/infra/tunnel/secrets.go index 2412ed0a2..d26718b12 100644 --- a/pkg/domain/infra/tunnel/secrets.go +++ b/pkg/domain/infra/tunnel/secrets.go @@ -2,12 +2,12 @@ package tunnel import ( "context" + "fmt" "io" "github.com/containers/podman/v4/pkg/bindings/secrets" "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/errorhandling" - "github.com/pkg/errors" ) func (ic *ContainerEngine) SecretCreate(ctx context.Context, name string, reader io.Reader, options entities.SecretCreateOptions) (*entities.SecretCreateReport, error) { @@ -33,7 +33,7 @@ func (ic *ContainerEngine) SecretInspect(ctx context.Context, nameOrIDs []string return nil, nil, err } if errModel.ResponseCode == 404 { - errs = append(errs, errors.Errorf("no such secret %q", name)) + errs = append(errs, fmt.Errorf("no such secret %q", name)) continue } return nil, nil, err @@ -73,7 +73,7 @@ func (ic *ContainerEngine) SecretRm(ctx context.Context, nameOrIDs []string, opt } if errModel.ResponseCode == 404 { allRm = append(allRm, &entities.SecretRmReport{ - Err: errors.Errorf("no secret with name or id %q: no such secret ", name), + Err: fmt.Errorf("no secret with name or id %q: no such secret ", name), ID: "", }) continue diff --git a/pkg/domain/infra/tunnel/volumes.go b/pkg/domain/infra/tunnel/volumes.go index 6ec35e836..b70d29783 100644 --- a/pkg/domain/infra/tunnel/volumes.go +++ b/pkg/domain/infra/tunnel/volumes.go @@ -2,12 +2,13 @@ package tunnel import ( "context" + "errors" + "fmt" "github.com/containers/podman/v4/pkg/bindings/volumes" "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/domain/entities/reports" "github.com/containers/podman/v4/pkg/errorhandling" - "github.com/pkg/errors" ) func (ic *ContainerEngine) VolumeCreate(ctx context.Context, opts entities.VolumeCreateOptions) (*entities.IDOrNameResponse, error) { @@ -64,7 +65,7 @@ func (ic *ContainerEngine) VolumeInspect(ctx context.Context, namesOrIds []strin return nil, nil, err } if errModel.ResponseCode == 404 { - errs = append(errs, errors.Errorf("no such volume %q", id)) + errs = append(errs, fmt.Errorf("no such volume %q", id)) continue } return nil, nil, err diff --git a/pkg/domain/utils/scp.go b/pkg/domain/utils/scp.go index a4ff6b950..3c73cddd1 100644 --- a/pkg/domain/utils/scp.go +++ b/pkg/domain/utils/scp.go @@ -20,7 +20,6 @@ import ( "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/terminal" "github.com/docker/distribution/reference" - "github.com/pkg/errors" "github.com/sirupsen/logrus" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/agent" @@ -44,7 +43,7 @@ func ExecuteTransfer(src, dst string, parentFlags []string, quiet bool) (*entiti confR, err := config.NewConfig("") // create a hand made config for the remote engine since we might use remote and native at once if err != nil { - return nil, nil, nil, nil, errors.Wrapf(err, "could not make config") + return nil, nil, nil, nil, fmt.Errorf("could not make config: %w", err) } cfg, err := config.ReadCustomConfig() // get ready to set ssh destination if necessary @@ -75,9 +74,9 @@ func ExecuteTransfer(src, dst string, parentFlags []string, quiet bool) (*entiti case len(locations) == 1: switch { case len(locations[0].Image) == 0: - return nil, nil, nil, nil, errors.Wrapf(define.ErrInvalidArg, "no source image specified") + return nil, nil, nil, nil, fmt.Errorf("no source image specified: %w", define.ErrInvalidArg) case len(locations[0].Image) > 0 && !locations[0].Remote && len(locations[0].User) == 0: // if we have podman image scp $IMAGE - return nil, nil, nil, nil, errors.Wrapf(define.ErrInvalidArg, "must specify a destination") + return nil, nil, nil, nil, fmt.Errorf("must specify a destination: %w", define.ErrInvalidArg) } } @@ -158,7 +157,7 @@ func ExecuteTransfer(src, dst string, parentFlags []string, quiet bool) (*entiti if source.User == "" { u, err := user.Current() if err != nil { - return nil, nil, nil, nil, errors.Wrapf(err, "could not obtain user, make sure the environmental variable $USER is set") + return nil, nil, nil, nil, fmt.Errorf("could not obtain user, make sure the environmental variable $USER is set: %w", err) } source.User = u.Username } @@ -231,11 +230,11 @@ func LoadToRemote(dest entities.ImageScpOptions, localFile string, tag string, u n, err := scpD.CopyTo(dial, localFile, remoteFile) if err != nil { errOut := strconv.Itoa(int(n)) + " Bytes copied before error" - return " ", "", errors.Wrapf(err, errOut) + return " ", "", fmt.Errorf("%v: %w", errOut, err) } var run string if tag != "" { - return "", "", errors.Wrapf(define.ErrInvalidArg, "Renaming of an image is currently not supported") + return "", "", fmt.Errorf("renaming of an image is currently not supported: %w", define.ErrInvalidArg) } podman := os.Args[0] run = podman + " image load --input=" + remoteFile + ";rm " + remoteFile // run ssh image load of the file copied via scp @@ -268,7 +267,7 @@ func SaveToRemote(image, localFile string, tag string, uri *url.URL, iden string defer dial.Close() if tag != "" { - return errors.Wrapf(define.ErrInvalidArg, "Renaming of an image is currently not supported") + return fmt.Errorf("renaming of an image is currently not supported: %w", define.ErrInvalidArg) } podman := os.Args[0] run := podman + " image save " + image + " --format=oci-archive --output=" + remoteFile // run ssh image load of the file copied via scp. Files are reverse in this case... @@ -282,7 +281,7 @@ func SaveToRemote(image, localFile string, tag string, uri *url.URL, iden string } if err != nil { errOut := strconv.Itoa(int(n)) + " Bytes copied before error" - return errors.Wrapf(err, errOut) + return fmt.Errorf("%v: %w", errOut, err) } return nil } @@ -307,7 +306,7 @@ func CreateConnection(url *url.URL, iden string) (*ssh.Client, string, error) { } dialAdd, err := ssh.Dial("tcp", url.Host, cfg) // dial the client if err != nil { - return nil, "", errors.Wrapf(err, "failed to connect") + return nil, "", fmt.Errorf("failed to connect: %w", err) } file, err := MakeRemoteFile(dialAdd) if err != nil { @@ -429,14 +428,14 @@ func ValidateImagePortion(location entities.ImageScpOptions, arg string) (entiti // validateSCPArgs takes the array of source and destination options and checks for common errors func ValidateSCPArgs(locations []*entities.ImageScpOptions) error { if len(locations) > 2 { - return errors.Wrapf(define.ErrInvalidArg, "cannot specify more than two arguments") + return fmt.Errorf("cannot specify more than two arguments: %w", define.ErrInvalidArg) } switch { case len(locations[0].Image) > 0 && len(locations[1].Image) > 0: locations[1].Tag = locations[1].Image locations[1].Image = "" case len(locations[0].Image) == 0 && len(locations[1].Image) == 0: - return errors.Wrapf(define.ErrInvalidArg, "a source image must be specified") + return fmt.Errorf("a source image must be specified: %w", define.ErrInvalidArg) } return nil } @@ -475,7 +474,7 @@ func ExecRemoteCommand(dial *ssh.Client, run string) ([]byte, error) { sess.Stdout = &buffer // output from client funneled into buffer sess.Stderr = &bufferErr // err form client funneled into buffer if err := sess.Run(run); err != nil { // run the command on the ssh client - return nil, errors.Wrapf(err, bufferErr.String()) + return nil, fmt.Errorf("%v: %w", bufferErr.String(), err) } return buffer.Bytes(), nil } @@ -488,12 +487,12 @@ func GetUserInfo(uri *url.URL) (*url.Userinfo, error) { if u, found := os.LookupEnv("_CONTAINERS_ROOTLESS_UID"); found { usr, err = user.LookupId(u) if err != nil { - return nil, errors.Wrapf(err, "failed to lookup rootless user") + return nil, fmt.Errorf("failed to lookup rootless user: %w", err) } } else { usr, err = user.Current() if err != nil { - return nil, errors.Wrapf(err, "failed to obtain current user") + return nil, fmt.Errorf("failed to obtain current user: %w", err) } } @@ -514,7 +513,7 @@ func ValidateAndConfigure(uri *url.URL, iden string) (*ssh.ClientConfig, error) value := iden s, err := terminal.PublicKey(value, []byte(passwd)) if err != nil { - return nil, errors.Wrapf(err, "failed to read identity %q", value) + return nil, fmt.Errorf("failed to read identity %q: %w", value, err) } signers = append(signers, s) logrus.Debugf("SSH Ident Key %q %s %s", value, ssh.FingerprintSHA256(s.PublicKey()), s.PublicKey().Type()) diff --git a/pkg/domain/utils/secrets_filters.go b/pkg/domain/utils/secrets_filters.go index e76bc592f..ab9b681ec 100644 --- a/pkg/domain/utils/secrets_filters.go +++ b/pkg/domain/utils/secrets_filters.go @@ -1,11 +1,11 @@ package utils import ( + "fmt" "strings" "github.com/containers/common/pkg/secrets" "github.com/containers/podman/v4/pkg/util" - "github.com/pkg/errors" ) func IfPassesSecretsFilter(s secrets.Secret, filters map[string][]string) (bool, error) { @@ -17,7 +17,7 @@ func IfPassesSecretsFilter(s secrets.Secret, filters map[string][]string) (bool, case "id": result = util.StringMatchRegexSlice(s.ID, filterValues) default: - return false, errors.Errorf("invalid filter %q", key) + return false, fmt.Errorf("invalid filter %q", key) } } return result, nil |