From 83a0e97ab81b1883fa4c807eaf075e8795757434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Sj=C3=B6lund?= Date: Sat, 4 Feb 2023 16:02:29 +0100 Subject: [PATCH] Add missing return after errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add missing return after utils.Error(), utils.InternalServerError(), utils.BadRequest(). [NO NEW TESTS NEEDED] Signed-off-by: Erik Sjölund --- pkg/api/handlers/compat/images.go | 1 + pkg/api/handlers/compat/images_build.go | 4 ++++ pkg/api/handlers/libpod/containers.go | 4 ++++ pkg/api/handlers/libpod/networks.go | 1 + 4 files changed, 10 insertions(+) diff --git a/pkg/api/handlers/compat/images.go b/pkg/api/handlers/compat/images.go index d61df5232e..34f721a882 100644 --- a/pkg/api/handlers/compat/images.go +++ b/pkg/api/handlers/compat/images.go @@ -201,6 +201,7 @@ func CreateImageFromSrc(w http.ResponseWriter, r *http.Request) { source = f.Name() if err := SaveFromBody(f, r); err != nil { utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to write temporary file: %w", err)) + return } } diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index ec53cea8cd..307adfc1a7 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -188,10 +188,12 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { anchorDir, err := os.MkdirTemp(parse.GetTempDir(), "libpod_builder") if err != nil { utils.InternalServerError(w, err) + return } tempDir, subDir, err := buildahDefine.TempDirForURL(anchorDir, "buildah", query.Remote) if err != nil { utils.InternalServerError(w, err) + return } if tempDir != "" { // We had to download it to a temporary directory. @@ -209,6 +211,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { absDir, err := filepath.Abs(query.Remote) if err != nil { utils.BadRequest(w, "remote", query.Remote, err) + return } contextDirectory = absDir } @@ -232,6 +235,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { containerFiles = []string{filepath.Join(contextDirectory, "Dockerfile")} if _, err1 := os.Stat(containerFiles[0]); err1 != nil { utils.BadRequest(w, "dockerfile", query.Dockerfile, err) + return } } } diff --git a/pkg/api/handlers/libpod/containers.go b/pkg/api/handlers/libpod/containers.go index 9d18c9420f..5866d23117 100644 --- a/pkg/api/handlers/libpod/containers.go +++ b/pkg/api/handlers/libpod/containers.go @@ -163,6 +163,7 @@ func UnmountContainer(w http.ResponseWriter, r *http.Request) { // "container not mounted" error so we can surface that to the endpoint user if err := conn.Unmount(false); err != nil { utils.InternalServerError(w, err) + return } utils.WriteResponse(w, http.StatusNoContent, "") } @@ -178,6 +179,7 @@ func MountContainer(w http.ResponseWriter, r *http.Request) { m, err := conn.Mount() if err != nil { utils.InternalServerError(w, err) + return } utils.WriteResponse(w, http.StatusOK, m) } @@ -188,11 +190,13 @@ func ShowMountedContainers(w http.ResponseWriter, r *http.Request) { conns, err := runtime.GetAllContainers() if err != nil { utils.InternalServerError(w, err) + return } for _, conn := range conns { mounted, mountPoint, err := conn.Mounted() if err != nil { utils.InternalServerError(w, err) + return } if !mounted { continue diff --git a/pkg/api/handlers/libpod/networks.go b/pkg/api/handlers/libpod/networks.go index 20ab695e16..13a38a9977 100644 --- a/pkg/api/handlers/libpod/networks.go +++ b/pkg/api/handlers/libpod/networks.go @@ -68,6 +68,7 @@ func UpdateNetwork(w http.ResponseWriter, r *http.Request) { err := ic.NetworkUpdate(r.Context(), name, networkUpdateOptions) if err != nil { utils.Error(w, http.StatusInternalServerError, err) + return } utils.WriteResponse(w, http.StatusNoContent, nil)