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

Side by Side Diff: common/errors/transient.go

Issue 1637193002: common/prpc, tools/cmd/cproto: prpc client (Closed) Base URL: https://github.com/luci/luci-go@prpc-server
Patch Set: Add some content length tests. Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | common/errors/wrap.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package errors 5 package errors
6 6
7 // Transient is an Error implementation. It wraps an existing Error, marking 7 // Transient is an Error implementation. It wraps an existing Error, marking
8 // it as transient. This can be tested with IsTransient. 8 // it as transient. This can be tested with IsTransient.
9 type Transient interface { 9 type Transient interface {
10 error 10 error
11 11
12 // IsTransient returns true if this error type is transient. 12 // IsTransient returns true if this error type is transient.
13 IsTransient() bool 13 IsTransient() bool
14 } 14 }
15 15
16 type transientWrapper struct { 16 type transientWrapper struct {
17 error 17 error
18 } 18 }
19 19
20 var _ interface {
21 Transient
22 Wrapped
23 } = transientWrapper{}
24
20 func (t transientWrapper) IsTransient() bool { 25 func (t transientWrapper) IsTransient() bool {
21 return true 26 return true
22 } 27 }
23 28
29 func (t transientWrapper) InnerError() error {
30 return t.error
31 }
32
24 // IsTransient tests if a given error is Transient. 33 // IsTransient tests if a given error is Transient.
25 func IsTransient(err error) bool { 34 func IsTransient(err error) bool {
26 if t, ok := err.(Transient); ok { 35 if t, ok := err.(Transient); ok {
27 return t.IsTransient() 36 return t.IsTransient()
28 } 37 }
29 return false 38 return false
30 } 39 }
31 40
32 // WrapTransient wraps an existing error with in a Transient error. 41 // WrapTransient wraps an existing error with in a Transient error.
33 // 42 //
34 // If the supplied error is already Transient, it will be returned. If the 43 // If the supplied error is already Transient, it will be returned. If the
35 // supplied error is nil, nil wil be returned. 44 // supplied error is nil, nil wil be returned.
36 func WrapTransient(err error) error { 45 func WrapTransient(err error) error {
37 if err == nil || IsTransient(err) { 46 if err == nil || IsTransient(err) {
38 return err 47 return err
39 } 48 }
40 return transientWrapper{err} 49 return transientWrapper{err}
41 } 50 }
OLDNEW
« no previous file with comments | « no previous file | common/errors/wrap.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698