Skip to content

Commit 0d1c73f

Browse files
committed
Eliminate need for outer error and use error from backoff.Retry
1 parent 2e0a42f commit 0d1c73f

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

internal/pkg/agent/application/actions/handlers/handler_helpers_windows.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,18 @@ const saveRetryDuration = 2 * time.Second
2525
// On Windows platforms, the save operation is retried if the error is an
2626
// ACCESS_DENIED error, which can happen if the file is locked by another process.
2727
func saveConfigToStore(store storage.Store, reader io.Reader) error {
28-
var saveErr error
2928
retryableSaveFn := func() error {
30-
saveErr = store.Save(reader)
31-
if errors.Is(saveErr, syscall.ERROR_ACCESS_DENIED) {
29+
err := store.Save(reader)
30+
if errors.Is(err, syscall.ERROR_ACCESS_DENIED) {
3231
// Retryable error, so return it
33-
return saveErr
32+
return err
3433
}
34+
3535
if err != nil {
3636
// Non-retryable error, so mark it as permanent
37-
return backoff.Permanent(saveErr)
37+
return backoff.Permanent(err)
3838
}
39-
// saveErr is an error that should not be retried. Return nil to
40-
// signal to the retrier that it should not retry.
39+
4140
return nil
4241
}
4342

@@ -49,8 +48,5 @@ func saveConfigToStore(store storage.Store, reader io.Reader) error {
4948
retryWithConstantBackoff := backoff.NewConstantBackOff(saveRetryInterval)
5049

5150
// Retry save operation
52-
//nolint:errcheck // ignore returned error because we're interested in the error from the save operation, saveErr
53-
backoff.Retry(retryableSaveFn, backoff.WithContext(retryWithConstantBackoff, retryCtx))
54-
55-
return saveErr
51+
return backoff.Retry(retryableSaveFn, backoff.WithContext(retryWithConstantBackoff, retryCtx))
5652
}

0 commit comments

Comments
 (0)