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

Unified Diff: common/errors/transient.go

Issue 2951393002: [errors] de-specialize Transient in favor of Tags. (Closed)
Patch Set: more refactor 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/errors/transient.go
diff --git a/common/errors/transient.go b/common/errors/transient.go
deleted file mode 100644
index 254e216edf2ffda9087a03a3f689a82583576d13..0000000000000000000000000000000000000000
--- a/common/errors/transient.go
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2015 The LUCI Authors. All rights reserved.
-// Use of this source code is governed under the Apache License, Version 2.0
-// that can be found in the LICENSE file.
-
-package errors
-
-// Transient is an Error implementation. It wraps an existing Error, marking
-// it as transient. This can be tested with IsTransient.
-type Transient interface {
- error
-
- // IsTransient returns true if this error type is transient.
- IsTransient() bool
-}
-
-type transientWrapper struct {
- error
- finfo StackFrameInfo
-}
-
-var _ interface {
- Transient
- StackContexter
-} = transientWrapper{}
-
-func (t transientWrapper) IsTransient() bool {
- return true
-}
-
-func (t transientWrapper) InnerError() error {
- return t.error
-}
-
-func (t transientWrapper) StackContext() StackContext {
- return StackContext{
- FrameInfo: t.finfo,
- InternalReason: "errors.WrapTransient()",
- }
-}
-
-// IsTransient tests if a given error or, if it is a container, any of its
-// contained errors is Transient.
-func IsTransient(err error) bool {
- return Any(err, func(err error) bool {
- if t, ok := err.(Transient); ok {
- return t.IsTransient()
- }
- return false
- })
-}
-
-// WrapTransient wraps an existing error with in a Transient error.
-//
-// If the supplied error is already Transient, it will be returned. If the
-// supplied error is nil, nil wil be returned.
-//
-// If the supplied error is not Transient, the current stack frame will be
-// captured. This wrapping action will show up on the stack trace returned by
-// RenderStack.
-func WrapTransient(err error) error {
- if err == nil || IsTransient(err) {
- return err
- }
- return transientWrapper{err, StackFrameInfoForError(1, err)}
-}

Powered by Google App Engine
This is Rietveld 408576698