diff --git a/client/task_runner.go b/client/task_runner.go index 8db5ffb09..984af2767 100644 --- a/client/task_runner.go +++ b/client/task_runner.go @@ -303,11 +303,10 @@ func (r *TaskRunner) run() { // Helper function for converting a WaitResult into a TaskTerminated event. func (r *TaskRunner) waitErrorToEvent(res *cstructs.WaitResult) *structs.TaskEvent { - e := structs.NewTaskEvent(structs.TaskTerminated).SetExitCode(res.ExitCode).SetSignal(res.Signal) - if res.Err != nil { - e.SetExitMessage(res.Err.Error()) - } - return e + return structs.NewTaskEvent(structs.TaskTerminated). + SetExitCode(res.ExitCode). + SetSignal(res.Signal). + SetExitMessage(res.Err) } // Update is used to update the task of the context diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 7c040e9d8..cdfdfa53e 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1128,8 +1128,10 @@ func (e *TaskEvent) SetSignal(s int) *TaskEvent { return e } -func (e *TaskEvent) SetExitMessage(m string) *TaskEvent { - e.Message = m +func (e *TaskEvent) SetExitMessage(err error) *TaskEvent { + if err != nil { + e.Message = err.Error() + } return e }