From 419b7aa2ba6c605ab714b56e9e7ac76db260d0fe Mon Sep 17 00:00:00 2001 From: KsaweryZietara Date: Wed, 18 Dec 2024 08:46:04 +0100 Subject: [PATCH] Do not override last error --- internal/process/operation_manager.go | 12 ++++++------ internal/process/staged_manager.go | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/process/operation_manager.go b/internal/process/operation_manager.go index c023f858e4..9c3caf7b12 100644 --- a/internal/process/operation_manager.go +++ b/internal/process/operation_manager.go @@ -30,13 +30,13 @@ func (om *OperationManager) OperationSucceeded(operation internal.Operation, des // OperationFailed marks the operation as failed and returns status of the operation's update func (om *OperationManager) OperationFailed(operation internal.Operation, description string, err error, log *slog.Logger) (internal.Operation, time.Duration, error) { + operation.LastError = kebErr.LastError{ + Message: description, + Component: om.component, + Step: om.step, + } if err != nil { - operation.LastError = kebErr.LastError{ - Message: err.Error(), - Reason: kebErr.Reason(description), - Component: om.component, - Step: om.step, - } + operation.LastError.Reason = kebErr.Reason(err.Error()) } op, t, _ := om.update(operation, domain.Failed, description, log) diff --git a/internal/process/staged_manager.go b/internal/process/staged_manager.go index eb5e5c5654..41a7bf9740 100644 --- a/internal/process/staged_manager.go +++ b/internal/process/staged_manager.go @@ -232,7 +232,6 @@ func (m *StagedManager) runStep(step Step, operation internal.Operation, logger stepLogger := logger.With("step", step.Name(), "operation", processedOperation.ID) processedOperation, backoff, err = step.Run(processedOperation, stepLogger) if err != nil { - processedOperation.LastError = kebError.ReasonForError(err, step.Name()) logOperation := stepLogger.With("error_component", processedOperation.LastError.GetComponent(), "error_reason", processedOperation.LastError.GetReason()) logOperation.Warn(fmt.Sprintf("Last error from step: %s", processedOperation.LastError.Error())) // only save to storage, skip for alerting if error