Skip to content

Commit

Permalink
extract context errors with context.Cause and not ctx.Err() to suppor…
Browse files Browse the repository at this point in the history
…t users using CancelCause
  • Loading branch information
NivKeidan committed Jun 10, 2024
1 parent 01d7e00 commit 37c4c88
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/avast/retry-go/v4

go 1.18
go 1.20

require github.com/stretchr/testify v1.9.0

Expand Down
10 changes: 5 additions & 5 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
opt(config)
}

if err := config.context.Err(); err != nil {
if err := context.Cause(config.context); err != nil {

Check failure on line 135 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.18, ubuntu-latest)

undefined: context.Cause

Check failure on line 135 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.19, ubuntu-latest)

undefined: context.Cause

Check failure on line 135 in retry.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: context.Cause (typecheck)

Check failure on line 135 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.18, macos-latest)

undefined: context.Cause

Check failure on line 135 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.19, macos-latest)

undefined: context.Cause

Check failure on line 135 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.18, windows-latest)

undefined: context.Cause

Check failure on line 135 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.19, windows-latest)

undefined: context.Cause
return emptyT, err
}

Expand Down Expand Up @@ -161,9 +161,9 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
case <-config.timer.After(delay(config, n, err)):
case <-config.context.Done():
if config.wrapContextErrorWithLastError {
return emptyT, Error{config.context.Err(), lastErr}
return emptyT, Error{context.Cause(config.context), lastErr}

Check failure on line 164 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.18, ubuntu-latest)

undefined: context.Cause

Check failure on line 164 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.19, ubuntu-latest)

undefined: context.Cause

Check failure on line 164 in retry.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: context.Cause (typecheck)

Check failure on line 164 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.18, macos-latest)

undefined: context.Cause

Check failure on line 164 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.19, macos-latest)

undefined: context.Cause

Check failure on line 164 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.18, windows-latest)

undefined: context.Cause

Check failure on line 164 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.19, windows-latest)

undefined: context.Cause
}
return emptyT, config.context.Err()
return emptyT, context.Cause(config.context)

Check failure on line 166 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.18, ubuntu-latest)

undefined: context.Cause

Check failure on line 166 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.19, ubuntu-latest)

undefined: context.Cause

Check failure on line 166 in retry.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: context.Cause (typecheck)

Check failure on line 166 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.18, macos-latest)

undefined: context.Cause

Check failure on line 166 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.19, macos-latest)

undefined: context.Cause

Check failure on line 166 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.18, windows-latest)

undefined: context.Cause

Check failure on line 166 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.19, windows-latest)

undefined: context.Cause
}
}
}
Expand Down Expand Up @@ -207,10 +207,10 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
case <-config.timer.After(delay(config, n, err)):
case <-config.context.Done():
if config.lastErrorOnly {
return emptyT, config.context.Err()
return emptyT, context.Cause(config.context)

Check failure on line 210 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.18, ubuntu-latest)

undefined: context.Cause

Check failure on line 210 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.19, ubuntu-latest)

undefined: context.Cause

Check failure on line 210 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.18, macos-latest)

undefined: context.Cause

Check failure on line 210 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.19, macos-latest)

undefined: context.Cause

Check failure on line 210 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.18, windows-latest)

undefined: context.Cause

Check failure on line 210 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.19, windows-latest)

undefined: context.Cause
}

return emptyT, append(errorLog, config.context.Err())
return emptyT, append(errorLog, context.Cause(config.context))

Check failure on line 213 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.18, ubuntu-latest)

undefined: context.Cause

Check failure on line 213 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.19, ubuntu-latest)

undefined: context.Cause

Check failure on line 213 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.18, macos-latest)

undefined: context.Cause

Check failure on line 213 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.19, macos-latest)

undefined: context.Cause

Check failure on line 213 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.18, windows-latest)

undefined: context.Cause

Check failure on line 213 in retry.go

View workflow job for this annotation

GitHub Actions / tests (1.19, windows-latest)

undefined: context.Cause
}

n++
Expand Down

0 comments on commit 37c4c88

Please sign in to comment.