Log job errors using progress logger (#337)

## Changes
This PR logs job errors using the progress logger

## Tests
Manually
This commit is contained in:
shreyas-goenka 2023-04-18 14:58:20 +02:00 committed by GitHub
parent 1a7b3eef18
commit 59eee11989
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -133,6 +133,9 @@ func (r *jobRunner) logFailedTasks(ctx context.Context, runId int64) {
log.Errorf(ctx, "task %s failed. Unable to fetch error trace: %s", red(task.TaskKey), err)
continue
}
if progressLogger, ok := cmdio.FromContext(ctx); ok {
progressLogger.Log(progress.NewTaskErrorEvent(task.TaskKey, taskInfo.Error, taskInfo.ErrorTrace))
}
log.Errorf(ctx, "Task %s failed!\nError:\n%s\nTrace:\n%s",
red(task.TaskKey), taskInfo.Error, taskInfo.ErrorTrace)
} else {

View File

@ -1,6 +1,35 @@
package progress
import "fmt"
import (
"fmt"
"strings"
)
type TaskErrorEvent struct {
TaskKey string `json:"task_key"`
Error string `json:"error"`
ErrorTrace string `json:"error_trace"`
}
func NewTaskErrorEvent(taskKey, errorMessage, errorTrace string) *TaskErrorEvent {
return &TaskErrorEvent{
TaskKey: taskKey,
Error: errorMessage,
ErrorTrace: errorTrace,
}
}
func (event *TaskErrorEvent) String() string {
result := strings.Builder{}
result.WriteString(fmt.Sprintf("Task %s FAILED:\n", event.TaskKey))
result.WriteString(event.Error + "\n")
result.WriteString(event.ErrorTrace + "\n")
return result.String()
}
func (event *TaskErrorEvent) IsInplaceSupported() bool {
return false
}
type JobRunUrlEvent struct {
Type string `json:"type"`