Skip to content

Commit cd803ff

Browse files
committed
BUGFIX: fix NIL error on error handling
1 parent 7df4798 commit cd803ff

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

prunner.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,11 @@ func findFirstFailedTaskByEndDate(tasks jobTasks) *jobTask {
552552
// Check if the task failed (has an error or non-zero exit code)
553553
if task.Errored {
554554
// If this is our first failed task or this one ended earlier than our current earliest
555-
if firstFailedTask == nil || task.End.Before(*firstFailedTask.End) {
555+
if firstFailedTask == nil {
556+
// we did not see any failed task yet. remember this one as the 1st failed task.
557+
firstFailedTask = task
558+
} else if firstFailedTask.End != nil && task.End != nil && task.End.Before(*firstFailedTask.End) {
559+
// this task has failed EARLIER than the one we already remembered.
556560
firstFailedTask = task
557561
}
558562
}
@@ -602,6 +606,11 @@ func (r *PipelineRunner) HandleTaskChange(t *task.Task) {
602606
// NOTE: this is NOT the context.Canceled case from above (if a job is explicitly aborted), but only
603607
// if one task failed, and we want to kill the other tasks.
604608
if jt.Errored {
609+
if jt.End == nil {
610+
// Remember ending time in case of error (we need this to identify the correct onError hook)
611+
now := time.Now()
612+
jt.End = &now
613+
}
605614
pipelineDef, found := r.defs.Pipelines[j.Pipeline]
606615
if found && !pipelineDef.ContinueRunningTasksAfterFailure {
607616
log.

prunner_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,20 @@ func TestPipelineRunner_ScheduleAsync_WithFailingScript_TriggersOnErrorHook(t *t
234234
"a": {
235235
Script: []string{"echo A"},
236236
},
237+
"c": {
238+
Script: []string{"sleep 10; exit 42"},
239+
DependsOn: []string{"b"},
240+
},
237241
"b": {
238242
Script: []string{
239243
"echo stdoutContent",
240244
"echo This message goes to stderr >&2",
241245
"exit 42",
242246
},
247+
DependsOn: []string{"a"},
243248
},
244249
"wait": {
245-
DependsOn: []string{"a", "b"},
250+
DependsOn: []string{"a", "b", "c"},
246251
},
247252
},
248253
OnError: &definition.OnErrorTaskDef{

0 commit comments

Comments
 (0)