Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(887)

Unified Diff: common/retry/transient.go

Issue 2951393002: [errors] de-specialize Transient in favor of Tags. (Closed)
Patch Set: copyright Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: common/retry/transient.go
diff --git a/common/retry/transient.go b/common/retry/transient.go
index fa641d446df9574cf752afbed012b4e1a08eb44a..6fbe3b37d6153bbd53fd1fffa58e2c8dc2f2c1c4 100644
--- a/common/retry/transient.go
+++ b/common/retry/transient.go
@@ -12,15 +12,13 @@ import (
)
// transientOnlyIterator is an Iterator implementation that only retries errors
-// if they are transient.
-//
-// (See errors.IsTransient).
+// if they are tagged with `retry.Tag`.
type transientOnlyIterator struct {
Iterator // The wrapped Iterator.
}
func (i *transientOnlyIterator) Next(ctx context.Context, err error) time.Duration {
- if !errors.IsTransient(err) {
+ if !Tag.In(err) {
return Stop
}
return i.Iterator.Next(ctx, err)
@@ -38,3 +36,11 @@ func TransientOnly(f Factory) Factory {
return &transientOnlyIterator{it}
})
}
+
+// Tag is used to indicate that an error should be retried by this package. Use
+// like:
+// err = retry.Tag.Apply(err)
+//
+// This allows libraries to preserve the original error, but indicate to the
+// retry library that the error may be transient.
+var Tag = errors.NewBoolTag("this error may go away with a retry")

Powered by Google App Engine
This is Rietveld 408576698