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

Unified Diff: common/errors/wrap.go

Issue 1637193002: common/prpc, tools/cmd/cproto: prpc client (Closed) Base URL: https://github.com/luci/luci-go@prpc-server
Patch Set: Add Context-derived timeout for Client. 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
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 {
iannucci 2016/01/27 02:55:49 Wrapped?
dnj (Google) 2016/01/27 03:24:25 Agreed, done.
+ // 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
+}

Powered by Google App Engine
This is Rietveld 408576698