refactor(daemon): name a taskrun failure's cause in one place

This commit is contained in:
sam committed 2026-10-24 11:32:16 +11:00
1 parent ec616e3b2f
commit 004177f0fb
1 file changed
+14 -7
+14 -7
View File
@@ -1899,14 +1899,12 @@ func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo conf
}
reply, err := d.requestTaskRun(ctx, task.ID, data)
if err != nil && stoppingOnly(ctx) {
d.Log.Info("daemon stopping; task left running for the next daemon to re-queue", "task", task.ID)
return
}
if cause := context.Cause(ctx); err != nil && (errors.Is(cause, errContainerExited) || errors.Is(cause, errTaskTimeLimit)) {
err = cause
}
if err != nil {
if stoppingOnly(ctx) {
d.Log.Info("daemon stopping; task left running for the next daemon to re-queue", "task", task.ID)
return
}
err = runFailure(ctx, err)
d.Log.Error("taskrun request failed", "task", task.ID, "err", err)
d.parkRunningTask(ctx, task, "taskrun request failed: "+err.Error(), taskstate.ParkTransient)
return
@@ -2499,6 +2497,15 @@ func (d *Daemon) markPoll(loop string) {
// stops before answering its taskrun request.
var errContainerExited = errors.New("agent container exited before the task finished")
// runFailure names why a taskrun request failed: the container's exit or the
// time limit when either cancelled it, else the request's own error.
func runFailure(ctx context.Context, err error) error {
if cause := context.Cause(ctx); errors.Is(cause, errContainerExited) || errors.Is(cause, errTaskTimeLimit) {
return cause
}
return err
}
// exitWatcher is a running agent container, seen only for how it ends.
type exitWatcher interface {
Exited() <-chan struct{}