Skip to content

Commit

Permalink
Do not override last error (#1584)
Browse files Browse the repository at this point in the history
* Do not override last error

* wip

* wip

* wip

* wip
  • Loading branch information
KsaweryZietara authored Dec 18, 2024
1 parent acf6c8f commit 14c8926
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
12 changes: 6 additions & 6 deletions internal/process/operation_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions internal/process/operation_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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())
})
}

Expand Down
1 change: 0 additions & 1 deletion internal/process/staged_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 14c8926

Please sign in to comment.