mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-06-28 23:24:35 +00:00
fix: guard SetJobError against missing job-error container (#1050)
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 <xiaolunwen@gmail.com> Co-authored-by: bircni <bircni@icloud.com> Co-committed-by: bircni <bircni@icloud.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user