From 8f72c60afa9b3ccdaf768d3111722ab594599fc0 Mon Sep 17 00:00:00 2001 From: bircni Date: Sun, 28 Jun 2026 08:50:41 +0000 Subject: [PATCH] fix: guard SetJobError against missing job-error container (#1050) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://gitea.com/gitea/runner/issues/1047 The runner panics during shutdown when jobs are interrupted: ``` panic in executor: interface conversion: interface {} is nil, not map[string]error ... gitea.com/gitea/runner/act/common.SetJobError(...) /data/gitea/runner/act/common/job_error.go:27 gitea.com/gitea/runner/act/runner.reportStepError(...) /data/gitea/runner/act/runner/job_executor.go:62 ``` `SetJobError` did an unchecked type assertion on the job-error container stored in the context: ```go ctx.Value(jobErrorContextKeyVal).(map[string]error)["error"] = err ``` When the container is absent — e.g. on shutdown, when a job is interrupted and `reportStepError` → `SetJobError` runs on a context where `WithJobErrorContainer` was never called — `ctx.Value` returns `nil` and asserting `nil.(map[string]error)` panics. ## Fix Use the comma-ok form so a missing container is a no-op, matching the safe pattern already used in the sibling `JobError` function. If there's no container, there's nowhere to record the error anyway, so skipping is correct. ```go func SetJobError(ctx context.Context, err error) { if container, ok := ctx.Value(jobErrorContextKeyVal).(map[string]error); ok { container["error"] = err } } ``` Reviewed-on: https://gitea.com/gitea/runner/pulls/1050 Reviewed-by: Lunny Xiao Co-authored-by: bircni Co-committed-by: bircni --- act/common/job_error.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/act/common/job_error.go b/act/common/job_error.go index 0575f29b..5ec617c8 100644 --- a/act/common/job_error.go +++ b/act/common/job_error.go @@ -24,7 +24,9 @@ func JobError(ctx context.Context) error { } func SetJobError(ctx context.Context, err error) { - ctx.Value(jobErrorContextKeyVal).(map[string]error)["error"] = err + if container, ok := ctx.Value(jobErrorContextKeyVal).(map[string]error); ok { + container["error"] = err + } } // WithJobErrorContainer adds a value to the context as a container for an error