From ec6d46bc8fe626c154fc46dd06d5fd0bf68248a7 Mon Sep 17 00:00:00 2001 From: Chongyi Zheng Date: Sun, 28 Apr 2024 00:13:57 -0400 Subject: [PATCH] Fix nil dereference on error (#30740) In both cases, the `err` is nil because of `if` checks before Reference: #30729 (cherry picked from commit 970965f6d8fb4e68613ca445d2414c6c796b5231) --- routers/api/actions/artifacts.go | 7 ++++--- routers/web/repo/actions/view.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/routers/api/actions/artifacts.go b/routers/api/actions/artifacts.go index 72ff70468..416d7e518 100644 --- a/routers/api/actions/artifacts.go +++ b/routers/api/actions/artifacts.go @@ -466,14 +466,15 @@ func (ar artifactRoutes) downloadArtifact(ctx *ArtifactContext) { log.Error("Error getting artifact: %v", err) ctx.Error(http.StatusInternalServerError, err.Error()) return - } else if !exist { + } + if !exist { log.Error("artifact with ID %d does not exist", artifactID) ctx.Error(http.StatusNotFound, fmt.Sprintf("artifact with ID %d does not exist", artifactID)) return } if artifact.RunID != runID { - log.Error("Error dismatch runID and artifactID, task: %v, artifact: %v", runID, artifactID) - ctx.Error(http.StatusBadRequest, err.Error()) + log.Error("Error mismatch runID and artifactID, task: %v, artifact: %v", runID, artifactID) + ctx.Error(http.StatusBadRequest) return } diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index 7d70d9f2a..dc21f1a4e 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -552,7 +552,7 @@ func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*actions return nil, nil } if len(jobs) == 0 { - ctx.Error(http.StatusNotFound, err.Error()) + ctx.Error(http.StatusNotFound) return nil, nil }