feat: add stacktrace parameter on retry#211
Conversation
retry/lib/retry.dart
Outdated
| int maxAttempts = 8, | ||
| FutureOr<bool> Function(Exception)? retryIf, | ||
| FutureOr<void> Function(Exception)? onRetry, | ||
| FutureOr<bool> Function(Exception, StackTrace)? retryIf, |
There was a problem hiding this comment.
I don't think users should be allowed to condition the retry on the stacktrace.
if you're doing this something is very wrong. It's probably better to fix the thing that is wrong.
There was a problem hiding this comment.
Yes, retryIf should not carry the stackTrace parameter.
Updated.
retry/lib/retry.dart
Outdated
| FutureOr<bool> Function(Exception)? retryIf, | ||
| FutureOr<void> Function(Exception)? onRetry, | ||
| FutureOr<bool> Function(Exception, StackTrace)? retryIf, | ||
| FutureOr<void> Function(Exception, StackTrace)? onRetry, |
There was a problem hiding this comment.
This could be useful, but is it worth doing a breaking change over this?
Maybe we can make a new optional parameter instead of onRetry or to complement onRetry. Like logRetry?
32672d6 to
120c252
Compare
retry/lib/retry.dart
Outdated
| FutureOr<T> Function() fn, { | ||
| FutureOr<bool> Function(Exception)? retryIf, | ||
| FutureOr<void> Function(Exception)? onRetry, | ||
| Function? onRetry, |
There was a problem hiding this comment.
With this we loose typing.
It's a valid way to solve this, but how about doing:
FutureOr<void> Function(Exception)? onRetry,
FutureOr<void> Function(Exception, StackTrace)? logRetry,Is there any reason we can't have both?
We could even do:
@Deprecated('Use `logRetry` instead of `onRetry`')
FutureOr<void> Function(Exception)? onRetry,
FutureOr<void> Function(Exception, StackTrace)? logRetry,There was a problem hiding this comment.
I wonder if there is an annotation or comment that'll allow us to hide the parameter from auto-completion :D
There was a problem hiding this comment.
@Deprecated('Use `onRetryFailure` instead of `onRetry`')
FutureOr<void> Function(Exception)? onRetry,
FutureOr<void> Function(Exception, StackTrace)? onRetryFailure,
Thank for review.
Updated.
Do you think 'onRetryFailure' would be a good name for this?
There was a problem hiding this comment.
Hmm, isn't logging the only legitimate use-case for onRetry, hence, logRetry might be a good name, or retryLog or???
We could also all it whenRetry.
There was a problem hiding this comment.
Hmm, we'll have a hard time breaking this API in the future. So I propose not making mistakes.
onRetryFailure is a bit long, and also implies that it should be called when retrying fails.
We could also call it onError, but that name is used else where to create an alternative value when an error happens.
I'm open to other ideas than logRetry, but let's try to keep it short and elegant :D
There was a problem hiding this comment.
I think of these names
- (i)
onFailure. regardless of whether Exception satisfiesretryIf, it will be called. - (ii)
onError. any error on retry, it will be called.
Which one do you think is better?
120c252 to
0c0e20c
Compare
Add stacktrace parameter on retryIf and onRetry function for getting additional information