From 14c8926b927274e446763a2d9b3df139bb36f102 Mon Sep 17 00:00:00 2001 From: KsaweryZietara <91937141+KsaweryZietara@users.noreply.github.com> Date: Wed, 18 Dec 2024 10:59:52 +0100 Subject: [PATCH] Do not override last error (#1584) * Do not override last error * wip * wip * wip * wip --- internal/process/operation_manager.go | 12 ++++++------ internal/process/operation_manager_test.go | 10 +++++----- internal/process/staged_manager.go | 1 - 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/internal/process/operation_manager.go b/internal/process/operation_manager.go index c023f858e4..5048bd107a 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{ + Reason: kebErr.Reason(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.Message = err.Error() } op, t, _ := om.update(operation, domain.Failed, description, log) diff --git a/internal/process/operation_manager_test.go b/internal/process/operation_manager_test.go index 0d3405697f..89c19988d1 100644 --- a/internal/process/operation_manager_test.go +++ b/internal/process/operation_manager_test.go @@ -118,10 +118,10 @@ func Test_OperationManager_LastError(t *testing.T) { err := operations.InsertOperation(op) require.NoError(t, err) op, _, err = opManager.OperationFailed(op, "friendly message", nil, fixLogger()) - assert.EqualValues(t, "", op.LastError.GetComponent()) + assert.EqualValues(t, "provisioner", op.LastError.GetComponent()) assert.EqualValues(t, "", op.LastError.Error()) - assert.EqualValues(t, "", op.LastError.GetReason()) - assert.EqualValues(t, "", op.LastError.GetStep()) + assert.EqualValues(t, "friendly message", op.LastError.GetReason()) + assert.EqualValues(t, "some_step", op.LastError.GetStep()) }) t.Run("when no description passed", func(t *testing.T) { @@ -146,10 +146,10 @@ func Test_OperationManager_LastError(t *testing.T) { err := operations.InsertOperation(op) require.NoError(t, err) op, _, err = opManager.OperationFailed(op, "", nil, fixLogger()) - assert.EqualValues(t, "", op.LastError.GetComponent()) + assert.EqualValues(t, "reconciler", op.LastError.GetComponent()) assert.EqualValues(t, "", op.LastError.Error()) assert.EqualValues(t, "", op.LastError.GetReason()) - assert.EqualValues(t, "", op.LastError.GetStep()) + assert.EqualValues(t, "some_step", op.LastError.GetStep()) }) } 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