From ffea506412e59e252c764806470af521d706f124 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Fri, 30 Jul 2021 12:50:36 +0200 Subject: [PATCH] Fix printing of EXECUTING_TASKS start message --- CHANGELOG.md | 2 ++ internal/batches/ui/json_lines.go | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f573b82db1..956d71fc70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ All notable changes to `src-cli` are documented in this file. ### Fixed +- For internal use only: `-text-only` silently ignored an error when trying to print log messages and did not print a `EXECUTING_TASKS` message. + ### Removed ## 3.30.2 diff --git a/internal/batches/ui/json_lines.go b/internal/batches/ui/json_lines.go index 12bcdcb317..33da1ee233 100644 --- a/internal/batches/ui/json_lines.go +++ b/internal/batches/ui/json_lines.go @@ -201,7 +201,10 @@ func logOperationProgress(op, msg string) { func logEvent(e batchesLogEvent) { e.Timestamp = time.Now().UTC().Truncate(time.Millisecond) - json.NewEncoder(os.Stdout).Encode(e) + err := json.NewEncoder(os.Stdout).Encode(e) + if err != nil { + fmt.Fprintln(os.Stderr, err) + } } // TODO: Until we've figured out what exactly we want to expose, we create @@ -223,18 +226,21 @@ type taskExecutionJSONLines struct { func (ui *taskExecutionJSONLines) Start(tasks []*executor.Task) { ui.linesTasks = make(map[*executor.Task]jsonLinesTask, len(tasks)) + var linesTasks []jsonLinesTask for _, t := range tasks { - ui.linesTasks[t] = jsonLinesTask{ + linesTask := jsonLinesTask{ Repository: t.Repository.Name, Workspace: t.Path, Steps: t.Steps, CachedStepResultsFound: t.CachedResultFound, StartStep: t.CachedResult.StepIndex, } + ui.linesTasks[t] = linesTask + linesTasks = append(linesTasks, linesTask) } logEvent(batchesLogEvent{Operation: "EXECUTING_TASKS", Status: "STARTED", Metadata: map[string]interface{}{ - "tasks": ui.linesTasks, + "tasks": linesTasks, }}) }