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

Unified Diff: common/errors/wrap.go

Issue 1605363002: common/prpc, tools/cmd/cproto: prpc client (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: rebased and addressed comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « common/errors/transient.go ('k') | common/logging/fields.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/errors/wrap.go
diff --git a/common/errors/wrap.go b/common/errors/wrap.go
new file mode 100644
index 0000000000000000000000000000000000000000..806b404822852266b613be05f16097da277cd33a
--- /dev/null
+++ b/common/errors/wrap.go
@@ -0,0 +1,33 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package errors
+
+// Wrap wraps an error.
+type Wrap interface {
+ // InnerError returns the wrapped error.
+ InnerError() error
+}
+
+// Unwrap returns the inner error of err.
+// Returns nil if err does not wrap anything or err is nil.
+func Unwrap(err error) error {
+ if wrap, ok := err.(Wrap); ok {
+ return wrap.InnerError()
+ }
+ return nil
+}
+
+// UnwrapAll unwraps a wrapped error recursively.
+// Returns nil iff err is nil.
+func UnwrapAll(err error) error {
+ for {
+ inner := Unwrap(err)
+ if inner == nil {
+ break
+ }
+ err = inner
+ }
+ return err
+}
« no previous file with comments | « common/errors/transient.go ('k') | common/logging/fields.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698