kubeslice / kubeslice/kubeslice-controller

Improvement: `util.Retry` uses `%s` instead of `%w`, discarding the error chain

Open Beginner friendly
#380 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
73
Forks
48
Avg merge
2d 21h
Merged PRs (30d)
8

Description

**Problem**:
`util.Retry` wraps the last error with `fmt.Errorf("retry failed after %d attempts ..., last error: %s", ..., err)`. Using `%s` converts the error to a string, discarding its type. Callers in `cleanup/service/cleanup-service.go` (lines 122, 147, 164, 182, 200, 229) cannot use `errors.Is` or `errors.As` to inspect the underlying cause. The fix is a one-character change from `%s` to `%w`.

**Proposed Solution**:
Change `%s` to `%w` at `util/common.go` line 219.

**Type of Issue**: improvement / error handling

## ✅ Expected Behavior

`errors.Is(err, someTargetErr)` works correctly on errors returned by `util.Retry`.

## 👎 Actual Behavior

The underlying error type is erased. `errors.Is` and `errors.As` always fail on `util.Retry` return values.

## ✅ Proposed Solution

Change line 219 of `util/common.go` from:
```go
return fmt.Errorf("retry failed after %d attempts (took %d seconds), last error: %s", backoffLimit, int(elapsed.Seconds()), err)
```
to:
```go
return fmt.Errorf("retry failed after %d attempts (took %d seconds), last error: %w", backoffLimit, int(elapsed.Seconds()), err)
```

## 👀 Have you spent some time to check if this issue has been raised before?
- [x] I checked and didn't find any similar issue

## Code of Conduct
- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Research direction

Start at util/common.go line 219 and inspect how util.Retry wraps its final error; review the listed cleanup/service/cleanup-service.go call sites for their error handling. Done means errors.Is and errors.As can inspect the underlying error returned by util.Retry while preserving the existing retry message and behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
86/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.