summaryrefslogtreecommitdiff
path: root/pkg/api
diff options
context:
space:
mode:
authoropenshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com>2022-07-05 16:10:12 +0000
committerGitHub <noreply@github.com>2022-07-05 16:10:12 +0000
commit39fc5d1f4f26f82ed1ca23d97f43924335c4c529 (patch)
treee0a54c6d0e3a1bc238cb5ef4a9316b55b39217ee /pkg/api
parent9539a89ee77682ed3f4d1d0be3b950523e2f2439 (diff)
parent251d91699de4e9aaab53ab6fea262d4b6bdaae8e (diff)
downloadpodman-39fc5d1f4f26f82ed1ca23d97f43924335c4c529.tar.gz
podman-39fc5d1f4f26f82ed1ca23d97f43924335c4c529.tar.bz2
podman-39fc5d1f4f26f82ed1ca23d97f43924335c4c529.zip
Merge pull request #14828 from saschagrunert/errors-libpod
libpod: switch to golang native error wrapping
Diffstat (limited to 'pkg/api')
-rw-r--r--pkg/api/handlers/compat/containers_archive.go18
-rw-r--r--pkg/api/handlers/compat/containers_create.go36
-rw-r--r--pkg/api/handlers/compat/containers_restart.go7
-rw-r--r--pkg/api/handlers/compat/containers_stop.go7
-rw-r--r--pkg/api/handlers/compat/exec.go19
-rw-r--r--pkg/api/handlers/compat/images.go68
-rw-r--r--pkg/api/handlers/compat/images_remove.go15
-rw-r--r--pkg/api/handlers/compat/networks.go46
-rw-r--r--pkg/api/handlers/compat/resize.go14
-rw-r--r--pkg/api/handlers/compat/secrets.go12
-rw-r--r--pkg/api/handlers/compat/volumes.go21
-rw-r--r--pkg/api/handlers/libpod/containers.go24
-rw-r--r--pkg/api/handlers/libpod/images.go90
-rw-r--r--pkg/api/handlers/libpod/networks.go18
-rw-r--r--pkg/api/handlers/utils/containers.go10
-rw-r--r--pkg/api/handlers/utils/images.go10
16 files changed, 212 insertions, 203 deletions
diff --git a/pkg/api/handlers/compat/containers_archive.go b/pkg/api/handlers/compat/containers_archive.go
index 77fbbe38a..cadfb7bd5 100644
--- a/pkg/api/handlers/compat/containers_archive.go
+++ b/pkg/api/handlers/compat/containers_archive.go
@@ -2,10 +2,13 @@ package compat
import (
"encoding/json"
+ "fmt"
"net/http"
"os"
"strings"
+ "errors"
+
"github.com/containers/podman/v4/libpod"
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/api/handlers/utils"
@@ -14,7 +17,6 @@ import (
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/domain/infra/abi"
"github.com/gorilla/schema"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -28,7 +30,7 @@ func Archive(w http.ResponseWriter, r *http.Request) {
case http.MethodHead, http.MethodGet:
handleHeadAndGet(w, r, decoder, runtime)
default:
- utils.Error(w, http.StatusNotImplemented, errors.Errorf("unsupported method: %v", r.Method))
+ utils.Error(w, http.StatusNotImplemented, fmt.Errorf("unsupported method: %v", r.Method))
}
}
@@ -39,7 +41,7 @@ func handleHeadAndGet(w http.ResponseWriter, r *http.Request, decoder *schema.De
err := decoder.Decode(&query, r.URL.Query())
if err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrap(err, "couldn't decode the query"))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("couldn't decode the query: %w", err))
return
}
@@ -65,7 +67,7 @@ func handleHeadAndGet(w http.ResponseWriter, r *http.Request, decoder *schema.De
w.Header().Add(copy.XDockerContainerPathStatHeader, statHeader)
}
- if errors.Cause(err) == define.ErrNoSuchCtr || errors.Cause(err) == copy.ErrENOENT {
+ if errors.Is(err, define.ErrNoSuchCtr) || errors.Is(err, copy.ErrENOENT) {
// 404 is returned for an absent container and path. The
// clients must deal with it accordingly.
utils.Error(w, http.StatusNotFound, err)
@@ -105,14 +107,14 @@ func handlePut(w http.ResponseWriter, r *http.Request, decoder *schema.Decoder,
err := decoder.Decode(&query, r.URL.Query())
if err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrap(err, "couldn't decode the query"))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("couldn't decode the query: %w", err))
return
}
var rename map[string]string
if query.Rename != "" {
if err := json.Unmarshal([]byte(query.Rename), &rename); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrap(err, "couldn't decode the query field 'rename'"))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("couldn't decode the query field 'rename': %w", err))
return
}
}
@@ -128,10 +130,10 @@ func handlePut(w http.ResponseWriter, r *http.Request, decoder *schema.Decoder,
})
if err != nil {
switch {
- case errors.Cause(err) == define.ErrNoSuchCtr || os.IsNotExist(err):
+ case errors.Is(err, define.ErrNoSuchCtr) || os.IsNotExist(err):
// 404 is returned for an absent container and path. The
// clients must deal with it accordingly.
- utils.Error(w, http.StatusNotFound, errors.Wrap(err, "the container doesn't exists"))
+ utils.Error(w, http.StatusNotFound, fmt.Errorf("the container doesn't exists: %w", err))
case strings.Contains(err.Error(), "copier: put: error creating file"):
// Not the best test but need to break this out for compatibility
// See vendor/github.com/containers/buildah/copier/copier.go:1585
diff --git a/pkg/api/handlers/compat/containers_create.go b/pkg/api/handlers/compat/containers_create.go
index 67ec52047..9fff8b4c8 100644
--- a/pkg/api/handlers/compat/containers_create.go
+++ b/pkg/api/handlers/compat/containers_create.go
@@ -2,6 +2,7 @@ package compat
import (
"encoding/json"
+ "errors"
"fmt"
"net"
"net/http"
@@ -26,7 +27,6 @@ import (
"github.com/containers/storage"
"github.com/docker/docker/api/types/mount"
"github.com/gorilla/schema"
- "github.com/pkg/errors"
)
func CreateContainer(w http.ResponseWriter, r *http.Request) {
@@ -38,14 +38,14 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
// override any golang type defaults
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
// compatible configuration
body := handlers.CreateContainerConfig{}
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("decode(): %w", err))
return
}
@@ -53,37 +53,37 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
body.Name = query.Name
if len(body.HostConfig.Links) > 0 {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(utils.ErrLinkNotSupport, "bad parameter"))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("bad parameter: %w", utils.ErrLinkNotSupport))
return
}
rtc, err := runtime.GetConfig()
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to get runtime config"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to get runtime config: %w", err))
return
}
imageName, err := utils.NormalizeToDockerHub(r, body.Config.Image)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "error normalizing image"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("error normalizing image: %w", err))
return
}
body.Config.Image = imageName
newImage, resolvedName, err := runtime.LibimageRuntime().LookupImage(body.Config.Image, nil)
if err != nil {
- if errors.Cause(err) == storage.ErrImageUnknown {
- utils.Error(w, http.StatusNotFound, errors.Wrap(err, "No such image"))
+ if errors.Is(err, storage.ErrImageUnknown) {
+ utils.Error(w, http.StatusNotFound, fmt.Errorf("no such image: %w", err))
return
}
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "error looking up image"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("error looking up image: %w", err))
return
}
// Take body structure and convert to cliopts
cliOpts, args, err := cliOpts(body, rtc)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "make cli opts()"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("make cli opts(): %w", err))
return
}
@@ -100,7 +100,7 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
sg := specgen.NewSpecGenerator(imgNameOrID, cliOpts.RootFS)
if err := specgenutil.FillOutSpecGen(sg, cliOpts, args); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "fill out specgen"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("fill out specgen: %w", err))
return
}
// moby always create the working directory
@@ -109,7 +109,7 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
ic := abi.ContainerEngine{Libpod: runtime}
report, err := ic.ContainerCreate(r.Context(), sg)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "container create"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("container create: %w", err))
return
}
createResponse := entities.ContainerCreateResponse{
@@ -300,7 +300,7 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C
if len(endpoint.IPAddress) > 0 {
staticIP := net.ParseIP(endpoint.IPAddress)
if staticIP == nil {
- return nil, nil, errors.Errorf("failed to parse the ip address %q", endpoint.IPAddress)
+ return nil, nil, fmt.Errorf("failed to parse the ip address %q", endpoint.IPAddress)
}
netOpts.StaticIPs = append(netOpts.StaticIPs, staticIP)
}
@@ -310,7 +310,7 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C
if len(endpoint.IPAMConfig.IPv4Address) > 0 {
staticIP := net.ParseIP(endpoint.IPAMConfig.IPv4Address)
if staticIP == nil {
- return nil, nil, errors.Errorf("failed to parse the ipv4 address %q", endpoint.IPAMConfig.IPv4Address)
+ return nil, nil, fmt.Errorf("failed to parse the ipv4 address %q", endpoint.IPAMConfig.IPv4Address)
}
netOpts.StaticIPs = append(netOpts.StaticIPs, staticIP)
}
@@ -318,7 +318,7 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C
if len(endpoint.IPAMConfig.IPv6Address) > 0 {
staticIP := net.ParseIP(endpoint.IPAMConfig.IPv6Address)
if staticIP == nil {
- return nil, nil, errors.Errorf("failed to parse the ipv6 address %q", endpoint.IPAMConfig.IPv6Address)
+ return nil, nil, fmt.Errorf("failed to parse the ipv6 address %q", endpoint.IPAMConfig.IPv6Address)
}
netOpts.StaticIPs = append(netOpts.StaticIPs, staticIP)
}
@@ -327,7 +327,7 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C
if len(endpoint.MacAddress) > 0 {
staticMac, err := net.ParseMAC(endpoint.MacAddress)
if err != nil {
- return nil, nil, errors.Errorf("failed to parse the mac address %q", endpoint.MacAddress)
+ return nil, nil, fmt.Errorf("failed to parse the mac address %q", endpoint.MacAddress)
}
netOpts.StaticMAC = types.HardwareAddr(staticMac)
}
@@ -433,7 +433,7 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C
}
if cc.HostConfig.Resources.NanoCPUs > 0 {
if cliOpts.CPUPeriod != 0 || cliOpts.CPUQuota != 0 {
- return nil, nil, errors.Errorf("NanoCpus conflicts with CpuPeriod and CpuQuota")
+ return nil, nil, fmt.Errorf("NanoCpus conflicts with CpuPeriod and CpuQuota")
}
cliOpts.CPUPeriod = 100000
cliOpts.CPUQuota = cc.HostConfig.Resources.NanoCPUs / 10000
@@ -479,7 +479,7 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C
}
if err := os.MkdirAll(vol, 0o755); err != nil {
if !os.IsExist(err) {
- return nil, nil, errors.Wrapf(err, "error making volume mountpoint for volume %s", vol)
+ return nil, nil, fmt.Errorf("error making volume mountpoint for volume %s: %w", vol, err)
}
}
}
diff --git a/pkg/api/handlers/compat/containers_restart.go b/pkg/api/handlers/compat/containers_restart.go
index ded6480bc..d805b95c2 100644
--- a/pkg/api/handlers/compat/containers_restart.go
+++ b/pkg/api/handlers/compat/containers_restart.go
@@ -1,6 +1,8 @@
package compat
import (
+ "errors"
+ "fmt"
"net/http"
"github.com/containers/podman/v4/libpod"
@@ -10,7 +12,6 @@ import (
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/domain/infra/abi"
"github.com/gorilla/schema"
- "github.com/pkg/errors"
)
func RestartContainer(w http.ResponseWriter, r *http.Request) {
@@ -29,7 +30,7 @@ func RestartContainer(w http.ResponseWriter, r *http.Request) {
// override any golang type defaults
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -44,7 +45,7 @@ func RestartContainer(w http.ResponseWriter, r *http.Request) {
}
report, err := containerEngine.ContainerRestart(r.Context(), []string{name}, options)
if err != nil {
- if errors.Cause(err) == define.ErrNoSuchCtr {
+ if errors.Is(err, define.ErrNoSuchCtr) {
utils.ContainerNotFound(w, name, err)
return
}
diff --git a/pkg/api/handlers/compat/containers_stop.go b/pkg/api/handlers/compat/containers_stop.go
index 1c1fb310c..33bb3a679 100644
--- a/pkg/api/handlers/compat/containers_stop.go
+++ b/pkg/api/handlers/compat/containers_stop.go
@@ -1,6 +1,8 @@
package compat
import (
+ "errors"
+ "fmt"
"net/http"
"github.com/containers/podman/v4/libpod"
@@ -10,7 +12,6 @@ import (
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/domain/infra/abi"
"github.com/gorilla/schema"
- "github.com/pkg/errors"
)
func StopContainer(w http.ResponseWriter, r *http.Request) {
@@ -29,7 +30,7 @@ func StopContainer(w http.ResponseWriter, r *http.Request) {
// override any golang type defaults
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -63,7 +64,7 @@ func StopContainer(w http.ResponseWriter, r *http.Request) {
}
report, err := containerEngine.ContainerStop(r.Context(), []string{name}, options)
if err != nil {
- if errors.Cause(err) == define.ErrNoSuchCtr {
+ if errors.Is(err, define.ErrNoSuchCtr) {
utils.ContainerNotFound(w, name, err)
return
}
diff --git a/pkg/api/handlers/compat/exec.go b/pkg/api/handlers/compat/exec.go
index a8b45c685..c7990f6e8 100644
--- a/pkg/api/handlers/compat/exec.go
+++ b/pkg/api/handlers/compat/exec.go
@@ -2,6 +2,8 @@ package compat
import (
"encoding/json"
+ "errors"
+ "fmt"
"net/http"
"strings"
@@ -14,7 +16,6 @@ import (
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/specgenutil"
"github.com/gorilla/mux"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -24,7 +25,7 @@ func ExecCreateHandler(w http.ResponseWriter, r *http.Request) {
input := new(handlers.ExecCreateConfig)
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
- utils.InternalServerError(w, errors.Wrapf(err, "error decoding request body as JSON"))
+ utils.InternalServerError(w, fmt.Errorf("error decoding request body as JSON: %w", err))
return
}
@@ -48,7 +49,7 @@ func ExecCreateHandler(w http.ResponseWriter, r *http.Request) {
for _, envStr := range input.Env {
split := strings.SplitN(envStr, "=", 2)
if len(split) != 2 {
- utils.Error(w, http.StatusBadRequest, errors.Errorf("environment variable %q badly formed, must be key=value", envStr))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("environment variable %q badly formed, must be key=value", envStr))
return
}
libpodConfig.Environment[split[0]] = split[1]
@@ -78,14 +79,14 @@ func ExecCreateHandler(w http.ResponseWriter, r *http.Request) {
sessID, err := ctr.ExecCreate(libpodConfig)
if err != nil {
- if errors.Cause(err) == define.ErrCtrStateInvalid {
+ if errors.Is(err, define.ErrCtrStateInvalid) {
// Check if the container is paused. If so, return a 409
state, err := ctr.State()
if err == nil {
// Ignore the error != nil case. We're already
// throwing an InternalServerError below.
if state == define.ContainerStatePaused {
- utils.Error(w, http.StatusConflict, errors.Errorf("cannot create exec session as container %s is paused", ctr.ID()))
+ utils.Error(w, http.StatusConflict, fmt.Errorf("cannot create exec session as container %s is paused", ctr.ID()))
return
}
}
@@ -112,7 +113,7 @@ func ExecInspectHandler(w http.ResponseWriter, r *http.Request) {
session, err := sessionCtr.ExecSession(sessionID)
if err != nil {
- utils.InternalServerError(w, errors.Wrapf(err, "error retrieving exec session %s from container %s", sessionID, sessionCtr.ID()))
+ utils.InternalServerError(w, fmt.Errorf("error retrieving exec session %s from container %s: %w", sessionID, sessionCtr.ID(), err))
return
}
@@ -135,7 +136,7 @@ func ExecStartHandler(w http.ResponseWriter, r *http.Request) {
bodyParams := new(handlers.ExecStartConfig)
if err := json.NewDecoder(r.Body).Decode(&bodyParams); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to decode parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to decode parameters for %s: %w", r.URL.String(), err))
return
}
// TODO: Verify TTY setting against what inspect session was made with
@@ -154,7 +155,7 @@ func ExecStartHandler(w http.ResponseWriter, r *http.Request) {
return
}
if state != define.ContainerStateRunning {
- utils.Error(w, http.StatusConflict, errors.Errorf("cannot exec in a container that is not running; container %s is %s", sessionCtr.ID(), state.String()))
+ utils.Error(w, http.StatusConflict, fmt.Errorf("cannot exec in a container that is not running; container %s is %s", sessionCtr.ID(), state.String()))
return
}
@@ -172,7 +173,7 @@ func ExecStartHandler(w http.ResponseWriter, r *http.Request) {
}
logErr := func(e error) {
- logrus.Error(errors.Wrapf(e, "error attaching to container %s exec session %s", sessionCtr.ID(), sessionID))
+ logrus.Error(fmt.Errorf("error attaching to container %s exec session %s: %w", sessionCtr.ID(), sessionID, e))
}
var size *define.TerminalSize
diff --git a/pkg/api/handlers/compat/images.go b/pkg/api/handlers/compat/images.go
index 981a38c35..2f8d151d8 100644
--- a/pkg/api/handlers/compat/images.go
+++ b/pkg/api/handlers/compat/images.go
@@ -2,6 +2,7 @@ package compat
import (
"encoding/json"
+ "errors"
"fmt"
"io/ioutil"
"net/http"
@@ -24,7 +25,6 @@ import (
"github.com/containers/storage"
"github.com/gorilla/schema"
"github.com/opencontainers/go-digest"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -50,7 +50,7 @@ func ExportImage(w http.ResponseWriter, r *http.Request) {
tmpfile, err := ioutil.TempFile("", "api.tar")
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to create tempfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempfile: %w", err))
return
}
defer os.Remove(tmpfile.Name())
@@ -58,7 +58,7 @@ func ExportImage(w http.ResponseWriter, r *http.Request) {
name := utils.GetName(r)
possiblyNormalizedName, err := utils.NormalizeToDockerHub(r, name)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "error normalizing image"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("error normalizing image: %w", err))
return
}
@@ -70,22 +70,22 @@ func ExportImage(w http.ResponseWriter, r *http.Request) {
}
if err := imageEngine.Save(r.Context(), possiblyNormalizedName, nil, saveOptions); err != nil {
- if errors.Cause(err) == storage.ErrImageUnknown {
- utils.ImageNotFound(w, name, errors.Wrapf(err, "failed to find image %s", name))
+ if errors.Is(err, storage.ErrImageUnknown) {
+ utils.ImageNotFound(w, name, fmt.Errorf("failed to find image %s: %w", name, err))
return
}
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to create tempfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempfile: %w", err))
return
}
if err := tmpfile.Close(); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to close tempfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to close tempfile: %w", err))
return
}
rdr, err := os.Open(tmpfile.Name())
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to read the exported tarfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to read the exported tarfile: %w", err))
return
}
defer rdr.Close()
@@ -111,12 +111,12 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) {
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
rtc, err := runtime.GetConfig()
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("Decode(): %w", err))
return
}
sc := runtime.SystemContext()
@@ -132,7 +132,7 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) {
input := handlers.CreateContainerConfig{}
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("Decode(): %w", err))
return
}
@@ -154,7 +154,7 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) {
destImage = fmt.Sprintf("%s:%s", query.Repo, query.Tag)
possiblyNormalizedName, err := utils.NormalizeToDockerHub(r, destImage)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "error normalizing image"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("error normalizing image: %w", err))
return
}
destImage = possiblyNormalizedName
@@ -162,7 +162,7 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) {
commitImage, err := ctr.Commit(r.Context(), destImage, options)
if err != nil && !strings.Contains(err.Error(), "is not running") {
- utils.Error(w, http.StatusInternalServerError, errors.Wrapf(err, "CommitFailure"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("CommitFailure: %w", err))
return
}
utils.WriteResponse(w, http.StatusCreated, entities.IDResponse{ID: commitImage.ID()})
@@ -186,7 +186,7 @@ func CreateImageFromSrc(w http.ResponseWriter, r *http.Request) {
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
// fromSrc – Source to import. The value may be a URL from which the image can be retrieved or - to read the image from the request body. This parameter may only be used when importing an image.
@@ -194,13 +194,13 @@ func CreateImageFromSrc(w http.ResponseWriter, r *http.Request) {
if source == "-" {
f, err := ioutil.TempFile("", "api_load.tar")
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to create tempfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to create tempfile: %w", err))
return
}
source = f.Name()
if err := SaveFromBody(f, r); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to write temporary file"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to write temporary file: %w", err))
}
}
@@ -208,7 +208,7 @@ func CreateImageFromSrc(w http.ResponseWriter, r *http.Request) {
if query.Repo != "" {
possiblyNormalizedName, err := utils.NormalizeToDockerHub(r, reference)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "error normalizing image"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("error normalizing image: %w", err))
return
}
reference = possiblyNormalizedName
@@ -229,7 +229,7 @@ func CreateImageFromSrc(w http.ResponseWriter, r *http.Request) {
imageEngine := abi.ImageEngine{Libpod: runtime}
report, err := imageEngine.Import(r.Context(), opts)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to import tarball"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to import tarball: %w", err))
return
}
// Success
@@ -265,13 +265,13 @@ func CreateImageFromImage(w http.ResponseWriter, r *http.Request) {
// This is where you can override the golang default value for one of fields
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
possiblyNormalizedName, err := utils.NormalizeToDockerHub(r, mergeNameAndTagOrDigest(query.FromImage, query.Tag))
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "error normalizing image"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("error normalizing image: %w", err))
return
}
@@ -388,7 +388,7 @@ func GetImage(w http.ResponseWriter, r *http.Request) {
name := utils.GetName(r)
possiblyNormalizedName, err := utils.NormalizeToDockerHub(r, name)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "error normalizing image"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("error normalizing image: %w", err))
return
}
@@ -397,12 +397,12 @@ func GetImage(w http.ResponseWriter, r *http.Request) {
// Here we need to fiddle with the error message because docker-py is looking for "No
// such image" to determine on how to raise the correct exception.
errMsg := strings.ReplaceAll(err.Error(), "image not known", "No such image")
- utils.Error(w, http.StatusNotFound, errors.Errorf("failed to find image %s: %s", name, errMsg))
+ utils.Error(w, http.StatusNotFound, fmt.Errorf("failed to find image %s: %s", name, errMsg))
return
}
inspect, err := handlers.ImageDataToImageInspect(r.Context(), newImage)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrapf(err, "failed to convert ImageData to ImageInspect '%s'", inspect.ID))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to convert ImageData to ImageInspect '%s': %w", inspect.ID, err))
return
}
utils.WriteResponse(w, http.StatusOK, inspect)
@@ -421,7 +421,7 @@ func GetImages(w http.ResponseWriter, r *http.Request) {
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, http.StatusBadRequest,
- errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
if _, found := r.URL.Query()["digests"]; found && query.Digests {
@@ -472,7 +472,7 @@ func LoadImages(w http.ResponseWriter, r *http.Request) {
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -480,7 +480,7 @@ func LoadImages(w http.ResponseWriter, r *http.Request) {
// to load.
f, err := ioutil.TempFile("", "api_load.tar")
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to create tempfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to create tempfile: %w", err))
return
}
defer func() {
@@ -490,7 +490,7 @@ func LoadImages(w http.ResponseWriter, r *http.Request) {
}
}()
if err := SaveFromBody(f, r); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to write temporary file"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to write temporary file: %w", err))
return
}
@@ -499,12 +499,12 @@ func LoadImages(w http.ResponseWriter, r *http.Request) {
loadOptions := entities.ImageLoadOptions{Input: f.Name()}
loadReport, err := imageEngine.Load(r.Context(), loadOptions)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to load image"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to load image: %w", err))
return
}
if len(loadReport.Names) < 1 {
- utils.Error(w, http.StatusInternalServerError, errors.Errorf("one or more images are required"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("one or more images are required"))
return
}
@@ -527,7 +527,7 @@ func ExportImages(w http.ResponseWriter, r *http.Request) {
// This is where you can override the golang default value for one of fields
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
if len(query.Names) == 0 {
@@ -539,7 +539,7 @@ func ExportImages(w http.ResponseWriter, r *http.Request) {
for i, img := range query.Names {
possiblyNormalizedName, err := utils.NormalizeToDockerHub(r, img)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "error normalizing image"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("error normalizing image: %w", err))
return
}
images[i] = possiblyNormalizedName
@@ -547,12 +547,12 @@ func ExportImages(w http.ResponseWriter, r *http.Request) {
tmpfile, err := ioutil.TempFile("", "api.tar")
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to create tempfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempfile: %w", err))
return
}
defer os.Remove(tmpfile.Name())
if err := tmpfile.Close(); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to close tempfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to close tempfile: %w", err))
return
}
@@ -566,7 +566,7 @@ func ExportImages(w http.ResponseWriter, r *http.Request) {
rdr, err := os.Open(tmpfile.Name())
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to read the exported tarfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to read the exported tarfile: %w", err))
return
}
defer rdr.Close()
diff --git a/pkg/api/handlers/compat/images_remove.go b/pkg/api/handlers/compat/images_remove.go
index 35bcb36aa..b59bfd0b1 100644
--- a/pkg/api/handlers/compat/images_remove.go
+++ b/pkg/api/handlers/compat/images_remove.go
@@ -1,6 +1,8 @@
package compat
import (
+ "errors"
+ "fmt"
"net/http"
"github.com/containers/podman/v4/libpod"
@@ -10,7 +12,6 @@ import (
"github.com/containers/podman/v4/pkg/domain/infra/abi"
"github.com/containers/storage"
"github.com/gorilla/schema"
- "github.com/pkg/errors"
)
func RemoveImage(w http.ResponseWriter, r *http.Request) {
@@ -25,7 +26,7 @@ func RemoveImage(w http.ResponseWriter, r *http.Request) {
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
if _, found := r.URL.Query()["noprune"]; found {
@@ -36,7 +37,7 @@ func RemoveImage(w http.ResponseWriter, r *http.Request) {
name := utils.GetName(r)
possiblyNormalizedName, err := utils.NormalizeToDockerHub(r, name)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "error normalizing image"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("error normalizing image: %w", err))
return
}
@@ -48,12 +49,12 @@ func RemoveImage(w http.ResponseWriter, r *http.Request) {
report, rmerrors := imageEngine.Remove(r.Context(), []string{possiblyNormalizedName}, options)
if len(rmerrors) > 0 && rmerrors[0] != nil {
err := rmerrors[0]
- if errors.Cause(err) == storage.ErrImageUnknown {
- utils.ImageNotFound(w, name, errors.Wrapf(err, "failed to find image %s", name))
+ if errors.Is(err, storage.ErrImageUnknown) {
+ utils.ImageNotFound(w, name, fmt.Errorf("failed to find image %s: %w", name, err))
return
}
- if errors.Cause(err) == storage.ErrImageUsedByContainer {
- utils.Error(w, http.StatusConflict, errors.Wrapf(err, "image %s is in use", name))
+ if errors.Is(err, storage.ErrImageUsedByContainer) {
+ utils.Error(w, http.StatusConflict, fmt.Errorf("image %s is in use: %w", name, err))
return
}
utils.Error(w, http.StatusInternalServerError, err)
diff --git a/pkg/api/handlers/compat/networks.go b/pkg/api/handlers/compat/networks.go
index 9da21d15f..65177218a 100644
--- a/pkg/api/handlers/compat/networks.go
+++ b/pkg/api/handlers/compat/networks.go
@@ -2,6 +2,7 @@ package compat
import (
"encoding/json"
+ "errors"
"fmt"
"net"
"net/http"
@@ -19,7 +20,6 @@ import (
dockerNetwork "github.com/docker/docker/api/types/network"
"github.com/gorilla/schema"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -36,7 +36,7 @@ func InspectNetwork(w http.ResponseWriter, r *http.Request) {
}
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -133,7 +133,7 @@ func ListNetworks(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
filterMap, err := util.PrepareFilters(r)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -167,7 +167,7 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) {
)
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
if err := json.NewDecoder(r.Body).Decode(&networkCreate); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("Decode(): %w", err))
return
}
@@ -227,7 +227,7 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) {
var err error
subnet, err := nettypes.ParseCIDR(conf.Subnet)
if err != nil {
- utils.InternalServerError(w, errors.Wrap(err, "failed to parse subnet"))
+ utils.InternalServerError(w, fmt.Errorf("failed to parse subnet: %w", err))
return
}
s.Subnet = subnet
@@ -235,7 +235,7 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) {
if len(conf.Gateway) > 0 {
gw := net.ParseIP(conf.Gateway)
if gw == nil {
- utils.InternalServerError(w, errors.Errorf("failed to parse gateway ip %s", conf.Gateway))
+ utils.InternalServerError(w, fmt.Errorf("failed to parse gateway ip %s", conf.Gateway))
return
}
s.Gateway = gw
@@ -243,17 +243,17 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) {
if len(conf.IPRange) > 0 {
_, net, err := net.ParseCIDR(conf.IPRange)
if err != nil {
- utils.InternalServerError(w, errors.Wrap(err, "failed to parse ip range"))
+ utils.InternalServerError(w, fmt.Errorf("failed to parse ip range: %w", err))
return
}
startIP, err := netutil.FirstIPInSubnet(net)
if err != nil {
- utils.InternalServerError(w, errors.Wrap(err, "failed to get first ip in range"))
+ utils.InternalServerError(w, fmt.Errorf("failed to get first ip in range: %w", err))
return
}
lastIP, err := netutil.LastIPInSubnet(net)
if err != nil {
- utils.InternalServerError(w, errors.Wrap(err, "failed to get last ip in range"))
+ utils.InternalServerError(w, fmt.Errorf("failed to get last ip in range: %w", err))
return
}
s.LeaseRange = &nettypes.LeaseRange{
@@ -296,7 +296,7 @@ func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -312,12 +312,12 @@ func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
return
}
if len(reports) == 0 {
- utils.Error(w, http.StatusInternalServerError, errors.Errorf("internal error"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("internal error"))
return
}
report := reports[0]
if report.Err != nil {
- if errors.Cause(report.Err) == define.ErrNoSuchNetwork {
+ if errors.Is(report.Err, define.ErrNoSuchNetwork) {
utils.Error(w, http.StatusNotFound, define.ErrNoSuchNetwork)
return
}
@@ -334,7 +334,7 @@ func Connect(w http.ResponseWriter, r *http.Request) {
var netConnect types.NetworkConnect
if err := json.NewDecoder(r.Body).Decode(&netConnect); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("Decode(): %w", err))
return
}
@@ -351,7 +351,7 @@ func Connect(w http.ResponseWriter, r *http.Request) {
staticIP := net.ParseIP(netConnect.EndpointConfig.IPAddress)
if staticIP == nil {
utils.Error(w, http.StatusInternalServerError,
- errors.Errorf("failed to parse the ip address %q", netConnect.EndpointConfig.IPAddress))
+ fmt.Errorf("failed to parse the ip address %q", netConnect.EndpointConfig.IPAddress))
return
}
netOpts.StaticIPs = append(netOpts.StaticIPs, staticIP)
@@ -363,7 +363,7 @@ func Connect(w http.ResponseWriter, r *http.Request) {
staticIP := net.ParseIP(netConnect.EndpointConfig.IPAMConfig.IPv4Address)
if staticIP == nil {
utils.Error(w, http.StatusInternalServerError,
- errors.Errorf("failed to parse the ipv4 address %q", netConnect.EndpointConfig.IPAMConfig.IPv4Address))
+ fmt.Errorf("failed to parse the ipv4 address %q", netConnect.EndpointConfig.IPAMConfig.IPv4Address))
return
}
netOpts.StaticIPs = append(netOpts.StaticIPs, staticIP)
@@ -373,7 +373,7 @@ func Connect(w http.ResponseWriter, r *http.Request) {
staticIP := net.ParseIP(netConnect.EndpointConfig.IPAMConfig.IPv6Address)
if staticIP == nil {
utils.Error(w, http.StatusInternalServerError,
- errors.Errorf("failed to parse the ipv6 address %q", netConnect.EndpointConfig.IPAMConfig.IPv6Address))
+ fmt.Errorf("failed to parse the ipv6 address %q", netConnect.EndpointConfig.IPAMConfig.IPv6Address))
return
}
netOpts.StaticIPs = append(netOpts.StaticIPs, staticIP)
@@ -384,7 +384,7 @@ func Connect(w http.ResponseWriter, r *http.Request) {
staticMac, err := net.ParseMAC(netConnect.EndpointConfig.MacAddress)
if err != nil {
utils.Error(w, http.StatusInternalServerError,
- errors.Errorf("failed to parse the mac address %q", netConnect.EndpointConfig.IPAMConfig.IPv6Address))
+ fmt.Errorf("failed to parse the mac address %q", netConnect.EndpointConfig.IPAMConfig.IPv6Address))
return
}
netOpts.StaticMAC = nettypes.HardwareAddr(staticMac)
@@ -392,11 +392,11 @@ func Connect(w http.ResponseWriter, r *http.Request) {
}
err := runtime.ConnectContainerToNetwork(netConnect.Container, name, netOpts)
if err != nil {
- if errors.Cause(err) == define.ErrNoSuchCtr {
+ if errors.Is(err, define.ErrNoSuchCtr) {
utils.ContainerNotFound(w, netConnect.Container, err)
return
}
- if errors.Cause(err) == define.ErrNoSuchNetwork {
+ if errors.Is(err, define.ErrNoSuchNetwork) {
utils.Error(w, http.StatusNotFound, err)
return
}
@@ -412,18 +412,18 @@ func Disconnect(w http.ResponseWriter, r *http.Request) {
var netDisconnect types.NetworkDisconnect
if err := json.NewDecoder(r.Body).Decode(&netDisconnect); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("Decode(): %w", err))
return
}
name := utils.GetName(r)
err := runtime.DisconnectContainerFromNetwork(netDisconnect.Container, name, netDisconnect.Force)
if err != nil {
- if errors.Cause(err) == define.ErrNoSuchCtr {
+ if errors.Is(err, define.ErrNoSuchCtr) {
utils.Error(w, http.StatusNotFound, err)
return
}
- if errors.Cause(err) == define.ErrNoSuchNetwork {
+ if errors.Is(err, define.ErrNoSuchNetwork) {
utils.Error(w, http.StatusNotFound, err)
return
}
@@ -438,7 +438,7 @@ func Prune(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
filterMap, err := util.PrepareFilters(r)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("Decode(): %w", err))
return
}
diff --git a/pkg/api/handlers/compat/resize.go b/pkg/api/handlers/compat/resize.go
index ce7340f62..f5da306da 100644
--- a/pkg/api/handlers/compat/resize.go
+++ b/pkg/api/handlers/compat/resize.go
@@ -1,6 +1,7 @@
package compat
import (
+ "errors"
"fmt"
"net/http"
"strings"
@@ -11,7 +12,6 @@ import (
api "github.com/containers/podman/v4/pkg/api/types"
"github.com/gorilla/mux"
"github.com/gorilla/schema"
- "github.com/pkg/errors"
)
func ResizeTTY(w http.ResponseWriter, r *http.Request) {
@@ -28,7 +28,7 @@ func ResizeTTY(w http.ResponseWriter, r *http.Request) {
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -47,8 +47,8 @@ func ResizeTTY(w http.ResponseWriter, r *http.Request) {
return
}
if err := ctnr.AttachResize(sz); err != nil {
- if errors.Cause(err) != define.ErrCtrStateInvalid {
- utils.InternalServerError(w, errors.Wrapf(err, "cannot resize container"))
+ if !errors.Is(err, define.ErrCtrStateInvalid) {
+ utils.InternalServerError(w, fmt.Errorf("cannot resize container: %w", err))
} else {
utils.Error(w, http.StatusConflict, err)
}
@@ -65,15 +65,15 @@ func ResizeTTY(w http.ResponseWriter, r *http.Request) {
return
}
if state, err := ctnr.State(); err != nil {
- utils.InternalServerError(w, errors.Wrapf(err, "cannot obtain session container state"))
+ utils.InternalServerError(w, fmt.Errorf("cannot obtain session container state: %w", err))
return
} else if state != define.ContainerStateRunning && !query.IgnoreNotRunning {
utils.Error(w, http.StatusConflict, fmt.Errorf("container %q in wrong state %q", name, state.String()))
return
}
if err := ctnr.ExecResize(name, sz); err != nil {
- if errors.Cause(err) != define.ErrExecSessionStateInvalid || !query.IgnoreNotRunning {
- utils.InternalServerError(w, errors.Wrapf(err, "cannot resize session"))
+ if !errors.Is(err, define.ErrExecSessionStateInvalid) || !query.IgnoreNotRunning {
+ utils.InternalServerError(w, fmt.Errorf("cannot resize session: %w", err))
return
}
}
diff --git a/pkg/api/handlers/compat/secrets.go b/pkg/api/handlers/compat/secrets.go
index 5031bf76b..13b3c4e24 100644
--- a/pkg/api/handlers/compat/secrets.go
+++ b/pkg/api/handlers/compat/secrets.go
@@ -4,7 +4,10 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
+ "errors"
+ "fmt"
"net/http"
+ "strings"
"github.com/containers/podman/v4/libpod"
"github.com/containers/podman/v4/pkg/api/handlers/utils"
@@ -12,14 +15,13 @@ import (
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/domain/infra/abi"
"github.com/containers/podman/v4/pkg/util"
- "github.com/pkg/errors"
)
func ListSecrets(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
filtersMap, err := util.PrepareFilters(r)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
ic := abi.ContainerEngine{Libpod: runtime}
@@ -106,11 +108,11 @@ func CreateSecret(w http.ResponseWriter, r *http.Request) {
}{}
if err := json.NewDecoder(r.Body).Decode(&createParams); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("Decode(): %w", err))
return
}
if len(createParams.Labels) > 0 {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(errors.New("bad parameter"), "labels not supported"))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("labels not supported: %w", errors.New("bad parameter")))
return
}
@@ -121,7 +123,7 @@ func CreateSecret(w http.ResponseWriter, r *http.Request) {
ic := abi.ContainerEngine{Libpod: runtime}
report, err := ic.SecretCreate(r.Context(), createParams.Name, reader, opts)
if err != nil {
- if errors.Cause(err).Error() == "secret name in use" {
+ if strings.Contains(err.Error(), "secret name in use") {
utils.Error(w, http.StatusConflict, err)
return
}
diff --git a/pkg/api/handlers/compat/volumes.go b/pkg/api/handlers/compat/volumes.go
index ff0a7af02..fe6ae36aa 100644
--- a/pkg/api/handlers/compat/volumes.go
+++ b/pkg/api/handlers/compat/volumes.go
@@ -3,6 +3,8 @@ package compat
import (
"bytes"
"encoding/json"
+ "errors"
+ "fmt"
"net/http"
"net/url"
"time"
@@ -18,7 +20,6 @@ import (
docker_api_types "github.com/docker/docker/api/types"
docker_api_types_volume "github.com/docker/docker/api/types/volume"
"github.com/gorilla/schema"
- "github.com/pkg/errors"
)
func ListVolumes(w http.ResponseWriter, r *http.Request) {
@@ -27,7 +28,7 @@ func ListVolumes(w http.ResponseWriter, r *http.Request) {
filtersMap, err := util.PrepareFilters(r)
if err != nil {
utils.Error(w, http.StatusInternalServerError,
- errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -36,7 +37,7 @@ func ListVolumes(w http.ResponseWriter, r *http.Request) {
for filter := range *filtersMap {
if filter == "opts" {
utils.Error(w, http.StatusInternalServerError,
- errors.Errorf("unsupported libpod filters passed to docker endpoint"))
+ fmt.Errorf("unsupported libpod filters passed to docker endpoint"))
return
}
}
@@ -86,13 +87,13 @@ func CreateVolume(w http.ResponseWriter, r *http.Request) {
query := struct{}{}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, http.StatusInternalServerError,
- errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
// decode params from body
input := docker_api_types_volume.VolumeCreateBody{}
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("Decode(): %w", err))
return
}
@@ -103,7 +104,7 @@ func CreateVolume(w http.ResponseWriter, r *http.Request) {
if len(input.Name) != 0 {
// See if the volume exists already
existingVolume, err = runtime.GetVolume(input.Name)
- if err != nil && errors.Cause(err) != define.ErrNoSuchVolume {
+ if err != nil && !errors.Is(err, define.ErrNoSuchVolume) {
utils.InternalServerError(w, err)
return
}
@@ -219,7 +220,7 @@ func RemoveVolume(w http.ResponseWriter, r *http.Request) {
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, http.StatusInternalServerError,
- errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -239,7 +240,7 @@ func RemoveVolume(w http.ResponseWriter, r *http.Request) {
if err == nil {
// As above, we do not pass `force` from the query parameters here
if err := runtime.RemoveVolume(r.Context(), vol, false, query.Timeout); err != nil {
- if errors.Cause(err) == define.ErrVolumeBeingUsed {
+ if errors.Is(err, define.ErrVolumeBeingUsed) {
utils.Error(w, http.StatusConflict, err)
} else {
utils.InternalServerError(w, err)
@@ -264,14 +265,14 @@ func PruneVolumes(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
filterMap, err := util.PrepareFilters(r)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("Decode(): %w", err))
return
}
f := (url.Values)(*filterMap)
filterFuncs, err := filters.GeneratePruneVolumeFilters(f)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrapf(err, "failed to parse filters for %s", f.Encode()))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to parse filters for %s: %w", f.Encode(), err))
return
}
diff --git a/pkg/api/handlers/libpod/containers.go b/pkg/api/handlers/libpod/containers.go
index deddcaf93..5d85d4009 100644
--- a/pkg/api/handlers/libpod/containers.go
+++ b/pkg/api/handlers/libpod/containers.go
@@ -1,6 +1,7 @@
package libpod
import (
+ "errors"
"fmt"
"io/ioutil"
"net/http"
@@ -16,7 +17,6 @@ import (
"github.com/containers/podman/v4/pkg/domain/infra/abi"
"github.com/containers/podman/v4/pkg/util"
"github.com/gorilla/schema"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -35,7 +35,7 @@ func ContainerExists(w http.ResponseWriter, r *http.Request) {
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -45,7 +45,7 @@ func ContainerExists(w http.ResponseWriter, r *http.Request) {
report, err := containerEngine.ContainerExists(r.Context(), name, options)
if err != nil {
- if errors.Cause(err) == define.ErrNoSuchCtr {
+ if errors.Is(err, define.ErrNoSuchCtr) {
utils.ContainerNotFound(w, name, err)
return
}
@@ -75,12 +75,12 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
filterMap, err := util.PrepareFilters(r)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrapf(err, "failed to decode filter parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to decode filter parameters for %s: %w", r.URL.String(), err))
return
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -127,7 +127,7 @@ func GetContainer(w http.ResponseWriter, r *http.Request) {
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
@@ -221,7 +221,7 @@ func Checkpoint(w http.ResponseWriter, r *http.Request) {
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -307,7 +307,7 @@ func Restore(w http.ResponseWriter, r *http.Request) {
// override any golang type defaults
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -344,11 +344,11 @@ func Restore(w http.ResponseWriter, r *http.Request) {
ir := abi.ImageEngine{Libpod: runtime}
report, err := ir.Exists(r.Context(), name)
if err != nil {
- utils.Error(w, http.StatusNotFound, errors.Wrapf(err, "failed to find container or checkpoint image %s", name))
+ utils.Error(w, http.StatusNotFound, fmt.Errorf("failed to find container or checkpoint image %s: %w", name, err))
return
}
if !report.Value {
- utils.Error(w, http.StatusNotFound, errors.Errorf("failed to find container or checkpoint image %s", name))
+ utils.Error(w, http.StatusNotFound, fmt.Errorf("failed to find container or checkpoint image %s", name))
return
}
}
@@ -380,7 +380,7 @@ func InitContainer(w http.ResponseWriter, r *http.Request) {
return
}
err = ctr.Init(r.Context(), ctr.PodID() != "")
- if errors.Cause(err) == define.ErrCtrStateInvalid {
+ if errors.Is(err, define.ErrCtrStateInvalid) {
utils.Error(w, http.StatusNotModified, err)
return
}
@@ -400,7 +400,7 @@ func ShouldRestart(w http.ResponseWriter, r *http.Request) {
name := utils.GetName(r)
report, err := containerEngine.ShouldRestart(r.Context(), name)
if err != nil {
- if errors.Cause(err) == define.ErrNoSuchCtr {
+ if errors.Is(err, define.ErrNoSuchCtr) {
utils.ContainerNotFound(w, name, err)
return
}
diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go
index b71217efa..ed1c65f8e 100644
--- a/pkg/api/handlers/libpod/images.go
+++ b/pkg/api/handlers/libpod/images.go
@@ -2,6 +2,7 @@ package libpod
import (
"context"
+ "errors"
"fmt"
"io"
"io/ioutil"
@@ -29,7 +30,6 @@ import (
utils2 "github.com/containers/podman/v4/utils"
"github.com/containers/storage"
"github.com/gorilla/schema"
- "github.com/pkg/errors"
)
// Commit
@@ -50,11 +50,11 @@ func ImageExists(w http.ResponseWriter, r *http.Request) {
ir := abi.ImageEngine{Libpod: runtime}
report, err := ir.Exists(r.Context(), name)
if err != nil {
- utils.Error(w, http.StatusNotFound, errors.Wrapf(err, "failed to find image %s", name))
+ utils.Error(w, http.StatusNotFound, fmt.Errorf("failed to find image %s: %w", name, err))
return
}
if !report.Value {
- utils.Error(w, http.StatusNotFound, errors.Errorf("failed to find image %s", name))
+ utils.Error(w, http.StatusNotFound, fmt.Errorf("failed to find image %s", name))
return
}
utils.WriteResponse(w, http.StatusNoContent, "")
@@ -70,18 +70,18 @@ func ImageTree(w http.ResponseWriter, r *http.Request) {
WhatRequires: false,
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
ir := abi.ImageEngine{Libpod: runtime}
options := entities.ImageTreeOptions{WhatRequires: query.WhatRequires}
report, err := ir.Tree(r.Context(), name, options)
if err != nil {
- if errors.Cause(err) == storage.ErrImageUnknown {
- utils.Error(w, http.StatusNotFound, errors.Wrapf(err, "failed to find image %s", name))
+ if errors.Is(err, storage.ErrImageUnknown) {
+ utils.Error(w, http.StatusNotFound, fmt.Errorf("failed to find image %s: %w", name, err))
return
}
- utils.Error(w, http.StatusInternalServerError, errors.Wrapf(err, "failed to generate image tree for %s", name))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to generate image tree for %s: %w", name, err))
return
}
utils.WriteResponse(w, http.StatusOK, report)
@@ -91,13 +91,13 @@ func GetImage(w http.ResponseWriter, r *http.Request) {
name := utils.GetName(r)
newImage, err := utils.GetImage(r, name)
if err != nil {
- utils.Error(w, http.StatusNotFound, errors.Wrapf(err, "failed to find image %s", name))
+ utils.Error(w, http.StatusNotFound, fmt.Errorf("failed to find image %s: %w", name, err))
return
}
options := &libimage.InspectOptions{WithParent: true, WithSize: true}
inspect, err := newImage.Inspect(r.Context(), options)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrapf(err, "failed in inspect image %s", inspect.ID))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed in inspect image %s: %w", inspect.ID, err))
return
}
utils.WriteResponse(w, http.StatusOK, inspect)
@@ -117,15 +117,13 @@ func PruneImages(w http.ResponseWriter, r *http.Request) {
filterMap, err := util.PrepareFilters(r)
if err != nil {
utils.Error(w, http.StatusInternalServerError,
- errors.
- Wrapf(err, "failed to decode filter parameters for %s", r.URL.String()))
+ fmt.Errorf("failed to decode filter parameters for %s: %w", r.URL.String(), err))
return
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, http.StatusInternalServerError,
- errors.
- Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -174,7 +172,7 @@ func ExportImage(w http.ResponseWriter, r *http.Request) {
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, http.StatusBadRequest,
- errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
name := utils.GetName(r)
@@ -188,23 +186,23 @@ func ExportImage(w http.ResponseWriter, r *http.Request) {
case define.OCIArchive, define.V2s2Archive:
tmpfile, err := ioutil.TempFile("", "api.tar")
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to create tempfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempfile: %w", err))
return
}
output = tmpfile.Name()
if err := tmpfile.Close(); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to close tempfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to close tempfile: %w", err))
return
}
case define.OCIManifestDir, define.V2s2ManifestDir:
tmpdir, err := ioutil.TempDir("", "save")
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to create tempdir"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempdir: %w", err))
return
}
output = tmpdir
default:
- utils.Error(w, http.StatusInternalServerError, errors.Errorf("unknown format %q", query.Format))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unknown format %q", query.Format))
return
}
@@ -233,7 +231,7 @@ func ExportImage(w http.ResponseWriter, r *http.Request) {
}
rdr, err := os.Open(output)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to read the exported tarfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to read the exported tarfile: %w", err))
return
}
defer rdr.Close()
@@ -254,20 +252,20 @@ func ExportImages(w http.ResponseWriter, r *http.Request) {
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
// References are mandatory!
if len(query.References) == 0 {
- utils.Error(w, http.StatusBadRequest, errors.New("No references"))
+ utils.Error(w, http.StatusBadRequest, errors.New("no references"))
return
}
// Format is mandatory! Currently, we only support multi-image docker
// archives.
if len(query.References) > 1 && query.Format != define.V2s2Archive {
- utils.Error(w, http.StatusInternalServerError, errors.Errorf("multi-image archives must use format of %s", define.V2s2Archive))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("multi-image archives must use format of %s", define.V2s2Archive))
return
}
@@ -285,23 +283,23 @@ func ExportImages(w http.ResponseWriter, r *http.Request) {
case define.V2s2Archive, define.OCIArchive:
tmpfile, err := ioutil.TempFile("", "api.tar")
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to create tempfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempfile: %w", err))
return
}
output = tmpfile.Name()
if err := tmpfile.Close(); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to close tempfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to close tempfile: %w", err))
return
}
case define.OCIManifestDir, define.V2s2ManifestDir:
tmpdir, err := ioutil.TempDir("", "save")
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to create tmpdir"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tmpdir: %w", err))
return
}
output = tmpdir
default:
- utils.Error(w, http.StatusInternalServerError, errors.Errorf("unsupported format %q", query.Format))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unsupported format %q", query.Format))
return
}
defer os.RemoveAll(output)
@@ -323,7 +321,7 @@ func ExportImages(w http.ResponseWriter, r *http.Request) {
rdr, err := os.Open(output)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to read the exported tarfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to read the exported tarfile: %w", err))
return
}
defer rdr.Close()
@@ -335,7 +333,7 @@ func ImagesLoad(w http.ResponseWriter, r *http.Request) {
tmpfile, err := ioutil.TempFile("", "libpod-images-load.tar")
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to create tempfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempfile: %w", err))
return
}
defer os.Remove(tmpfile.Name())
@@ -344,7 +342,7 @@ func ImagesLoad(w http.ResponseWriter, r *http.Request) {
tmpfile.Close()
if err != nil && err != io.EOF {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to write archive to temporary file"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to write archive to temporary file: %w", err))
return
}
@@ -353,7 +351,7 @@ func ImagesLoad(w http.ResponseWriter, r *http.Request) {
loadOptions := entities.ImageLoadOptions{Input: tmpfile.Name()}
loadReport, err := imageEngine.Load(r.Context(), loadOptions)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to load image"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to load image: %w", err))
return
}
utils.WriteResponse(w, http.StatusOK, loadReport)
@@ -375,7 +373,7 @@ func ImagesImport(w http.ResponseWriter, r *http.Request) {
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -384,14 +382,14 @@ func ImagesImport(w http.ResponseWriter, r *http.Request) {
if len(query.URL) == 0 {
tmpfile, err := ioutil.TempFile("", "libpod-images-import.tar")
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to create tempfile"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempfile: %w", err))
return
}
defer os.Remove(tmpfile.Name())
defer tmpfile.Close()
if _, err := io.Copy(tmpfile, r.Body); err != nil && err != io.EOF {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to write archive to temporary file"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to write archive to temporary file: %w", err))
return
}
@@ -411,7 +409,7 @@ func ImagesImport(w http.ResponseWriter, r *http.Request) {
}
report, err := imageEngine.Import(r.Context(), importOptions)
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to import tarball"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to import tarball: %w", err))
return
}
@@ -433,7 +431,7 @@ func PushImage(w http.ResponseWriter, r *http.Request) {
// This is where you can override the golang default value for one of fields
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -479,7 +477,7 @@ func PushImage(w http.ResponseWriter, r *http.Request) {
imageEngine := abi.ImageEngine{Libpod: runtime}
if err := imageEngine.Push(context.Background(), source, destination, options); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "error pushing image %q", destination))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("error pushing image %q: %w", destination, err))
return
}
@@ -509,12 +507,12 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) {
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
rtc, err := runtime.GetConfig()
if err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to get runtime config"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to get runtime config: %w", err))
return
}
sc := runtime.SystemContext()
@@ -532,7 +530,7 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) {
case "docker":
mimeType = manifest.DockerV2Schema2MediaType
default:
- utils.InternalServerError(w, errors.Errorf("unrecognized image format %q", query.Format))
+ utils.InternalServerError(w, fmt.Errorf("unrecognized image format %q", query.Format))
return
}
options.CommitOptions = buildah.CommitOptions{
@@ -561,7 +559,7 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) {
}
commitImage, err := ctr.Commit(r.Context(), destImage, options)
if err != nil && !strings.Contains(err.Error(), "is not running") {
- utils.Error(w, http.StatusInternalServerError, errors.Wrapf(err, "CommitFailure"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("CommitFailure: %w", err))
return
}
utils.WriteResponse(w, http.StatusOK, entities.IDResponse{ID: commitImage.ID()})
@@ -600,8 +598,8 @@ func UntagImage(w http.ResponseWriter, r *http.Request) {
name := utils.GetName(r)
if err := imageEngine.Untag(r.Context(), name, tags, opts); err != nil {
- if errors.Cause(err) == storage.ErrImageUnknown {
- utils.ImageNotFound(w, name, errors.Wrapf(err, "failed to find image %s", name))
+ if errors.Is(err, storage.ErrImageUnknown) {
+ utils.ImageNotFound(w, name, fmt.Errorf("failed to find image %s: %w", name, err))
} else {
utils.Error(w, http.StatusInternalServerError, err)
}
@@ -623,7 +621,7 @@ func ImagesBatchRemove(w http.ResponseWriter, r *http.Request) {
}{}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -647,7 +645,7 @@ func ImagesRemove(w http.ResponseWriter, r *http.Request) {
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -684,7 +682,7 @@ func ImageScp(w http.ResponseWriter, r *http.Request) {
// This is where you can override the golang default value for one of fields
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -697,7 +695,7 @@ func ImageScp(w http.ResponseWriter, r *http.Request) {
}
if source != nil || dest != nil {
- utils.Error(w, http.StatusBadRequest, errors.Wrapf(define.ErrInvalidArg, "cannot use the user transfer function on the remote client"))
+ utils.Error(w, http.StatusBadRequest, fmt.Errorf("cannot use the user transfer function on the remote client: %w", define.ErrInvalidArg))
return
}
diff --git a/pkg/api/handlers/libpod/networks.go b/pkg/api/handlers/libpod/networks.go
index 16f499d4c..7169a6d44 100644
--- a/pkg/api/handlers/libpod/networks.go
+++ b/pkg/api/handlers/libpod/networks.go
@@ -2,8 +2,11 @@ package libpod
import (
"encoding/json"
+ "fmt"
"net/http"
+ "errors"
+
"github.com/containers/common/libnetwork/types"
"github.com/containers/podman/v4/libpod"
"github.com/containers/podman/v4/libpod/define"
@@ -13,7 +16,6 @@ import (
"github.com/containers/podman/v4/pkg/domain/infra/abi"
"github.com/containers/podman/v4/pkg/util"
"github.com/gorilla/schema"
- "github.com/pkg/errors"
)
func CreateNetwork(w http.ResponseWriter, r *http.Request) {
@@ -25,7 +27,7 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
network := types.Network{}
if err := json.NewDecoder(r.Body).Decode(&network); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to decode request JSON payload"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to decode request JSON payload: %w", err))
return
}
@@ -52,7 +54,7 @@ func ListNetworks(w http.ResponseWriter, r *http.Request) {
filterMap, err := util.PrepareFilters(r)
if err != nil {
utils.Error(w, http.StatusInternalServerError,
- errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -83,7 +85,7 @@ func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, http.StatusInternalServerError,
- errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
name := utils.GetName(r)
@@ -99,7 +101,7 @@ func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
}
if reports[0].Err != nil {
// If the network cannot be found, we return a 404.
- if errors.Cause(reports[0].Err) == define.ErrNoSuchNetwork {
+ if errors.Is(reports[0].Err, define.ErrNoSuchNetwork) {
utils.Error(w, http.StatusNotFound, reports[0].Err)
return
}
@@ -142,18 +144,18 @@ func Connect(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
var netConnect entities.NetworkConnectOptions
if err := json.NewDecoder(r.Body).Decode(&netConnect); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to decode request JSON payload"))
+ utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to decode request JSON payload: %w", err))
return
}
name := utils.GetName(r)
err := runtime.ConnectContainerToNetwork(netConnect.Container, name, netConnect.PerNetworkOptions)
if err != nil {
- if errors.Cause(err) == define.ErrNoSuchCtr {
+ if errors.Is(err, define.ErrNoSuchCtr) {
utils.ContainerNotFound(w, netConnect.Container, err)
return
}
- if errors.Cause(err) == define.ErrNoSuchNetwork {
+ if errors.Is(err, define.ErrNoSuchNetwork) {
utils.Error(w, http.StatusNotFound, err)
return
}
diff --git a/pkg/api/handlers/utils/containers.go b/pkg/api/handlers/utils/containers.go
index 1795f6ce1..80f8522fd 100644
--- a/pkg/api/handlers/utils/containers.go
+++ b/pkg/api/handlers/utils/containers.go
@@ -2,6 +2,7 @@ package utils
import (
"context"
+ "errors"
"fmt"
"net/http"
"strconv"
@@ -19,7 +20,6 @@ import (
"github.com/containers/podman/v4/libpod"
"github.com/gorilla/schema"
- "github.com/pkg/errors"
)
type waitQueryDocker struct {
@@ -39,7 +39,7 @@ func WaitContainerDocker(w http.ResponseWriter, r *http.Request) {
decoder := ctx.Value(api.DecoderKey).(*schema.Decoder)
if err = decoder.Decode(&query, r.URL.Query()); err != nil {
- Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -106,7 +106,7 @@ func WaitContainerLibpod(w http.ResponseWriter, r *http.Request) {
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
query := waitQueryLibpod{}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
@@ -130,7 +130,7 @@ func WaitContainerLibpod(w http.ResponseWriter, r *http.Request) {
exitCode, err := waitFn(conditions...)
if err != nil {
- if errors.Cause(err) == define.ErrNoSuchCtr {
+ if errors.Is(err, define.ErrNoSuchCtr) {
ContainerNotFound(w, name, err)
return
}
@@ -197,7 +197,7 @@ var notRunningStates = []define.ContainerStatus{
func waitRemoved(ctrWait containerWaitFn) (int32, error) {
code, err := ctrWait(define.ContainerStateUnknown)
- if err != nil && errors.Cause(err) == define.ErrNoSuchCtr {
+ if err != nil && errors.Is(err, define.ErrNoSuchCtr) {
return code, nil
}
return code, err
diff --git a/pkg/api/handlers/utils/images.go b/pkg/api/handlers/utils/images.go
index 77f6dcf1d..357fa2990 100644
--- a/pkg/api/handlers/utils/images.go
+++ b/pkg/api/handlers/utils/images.go
@@ -1,6 +1,7 @@
package utils
import (
+ "errors"
"fmt"
"net/http"
"strings"
@@ -15,7 +16,6 @@ import (
"github.com/containers/podman/v4/pkg/util"
"github.com/containers/storage"
"github.com/docker/distribution/reference"
- "github.com/pkg/errors"
)
// NormalizeToDockerHub normalizes the specified nameOrID to Docker Hub if the
@@ -32,7 +32,7 @@ func NormalizeToDockerHub(r *http.Request, nameOrID string) (string, error) {
// 'busybox' -> 'registry.com/busybox'.
img, candidate, err := runtime.LibimageRuntime().LookupImage(nameOrID, nil)
if err != nil {
- if errors.Cause(err) != storage.ErrImageUnknown {
+ if !errors.Is(err, storage.ErrImageUnknown) {
return "", fmt.Errorf("normalizing name for compat API: %v", err)
}
// If the image could not be resolved locally, set the
@@ -73,7 +73,7 @@ func IsRegistryReference(name string) error {
if imageRef.Transport().Name() == docker.Transport.Name() {
return nil
}
- return errors.Errorf("unsupported transport %s in %q: only docker transport is supported", imageRef.Transport().Name(), name)
+ return fmt.Errorf("unsupported transport %s in %q: only docker transport is supported", imageRef.Transport().Name(), name)
}
// ParseStorageReference parses the specified image name to a
@@ -83,12 +83,12 @@ func ParseStorageReference(name string) (types.ImageReference, error) {
storagePrefix := storageTransport.Transport.Name()
imageRef, err := alltransports.ParseImageName(name)
if err == nil && imageRef.Transport().Name() != docker.Transport.Name() {
- return nil, errors.Errorf("reference %q must be a storage reference", name)
+ return nil, fmt.Errorf("reference %q must be a storage reference", name)
} else if err != nil {
origErr := err
imageRef, err = alltransports.ParseImageName(fmt.Sprintf("%s:%s", storagePrefix, name))
if err != nil {
- return nil, errors.Wrapf(origErr, "reference %q must be a storage reference", name)
+ return nil, fmt.Errorf("reference %q must be a storage reference: %w", name, origErr)
}
}
return imageRef, nil