From ee0f30551caa491187573252f186577eb6017f43 Mon Sep 17 00:00:00 2001 From: Sebastian Kurfuerst Date: Fri, 22 Dec 2023 13:43:30 +0100 Subject: [PATCH] fix issue detected by linter -> improve error handling --- prunner.go | 62 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/prunner.go b/prunner.go index 966b5af..d1eb480 100644 --- a/prunner.go +++ b/prunner.go @@ -487,17 +487,57 @@ func (r *PipelineRunner) runOnErrorScript(t *task.Task, j *PipelineJob, onErrorT WithField("failedTaskName", t.Name). Debug("Triggering onError Script because of task failure") - rc, _ := r.outputStore.Reader(j.ID.String(), t.Name, "stdout") - defer func(rc io.ReadCloser) { - _ = rc.Close() - }(rc) - failedTaskStdout, err := io.ReadAll(rc) - - rc, _ = r.outputStore.Reader(j.ID.String(), t.Name, "stderr") - defer func(rc io.ReadCloser) { - _ = rc.Close() - }(rc) - failedTaskStderr, err := io.ReadAll(rc) + var failedTaskStdout []byte + rc, err := r.outputStore.Reader(j.ID.String(), t.Name, "stdout") + if err != nil { + log. + WithField("component", "runner"). + WithField("jobID", j.ID.String()). + WithField("pipeline", j.Pipeline). + WithField("failedTaskName", t.Name). + WithError(err). + Debug("Could not create stdoutReader for failed task") + } else { + defer func(rc io.ReadCloser) { + _ = rc.Close() + }(rc) + failedTaskStdout, err = io.ReadAll(rc) + if err != nil { + log. + WithField("component", "runner"). + WithField("jobID", j.ID.String()). + WithField("pipeline", j.Pipeline). + WithField("failedTaskName", t.Name). + WithError(err). + Debug("Could not read stdout of failed task") + } + } + + var failedTaskStderr []byte + rc, err = r.outputStore.Reader(j.ID.String(), t.Name, "stderr") + if err != nil { + log. + WithField("component", "runner"). + WithField("jobID", j.ID.String()). + WithField("pipeline", j.Pipeline). + WithField("failedTaskName", t.Name). + WithError(err). + Debug("Could not create stderrReader for failed task") + } else { + defer func(rc io.ReadCloser) { + _ = rc.Close() + }(rc) + failedTaskStderr, err = io.ReadAll(rc) + if err != nil { + log. + WithField("component", "runner"). + WithField("jobID", j.ID.String()). + WithField("pipeline", j.Pipeline). + WithField("failedTaskName", t.Name). + WithError(err). + Debug("Could not read stderr of failed task") + } + } onErrorVariables := make(map[string]interface{}) for key, value := range j.Variables {