OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package errors | |
6 | |
7 // Wrap wraps an error. | |
8 type Wrap interface { | |
iannucci
2016/01/27 02:55:49
Wrapped?
dnj (Google)
2016/01/27 03:24:25
Agreed, done.
| |
9 // InnerError returns the wrapped error. | |
10 InnerError() error | |
11 } | |
12 | |
13 // Unwrap returns the inner error of err. | |
14 // Returns nil if err does not wrap anything or err is nil. | |
15 func Unwrap(err error) error { | |
16 if wrap, ok := err.(Wrap); ok { | |
17 return wrap.InnerError() | |
18 } | |
19 return nil | |
20 } | |
21 | |
22 // UnwrapAll unwraps a wrapped error recursively. | |
23 // Returns nil iff err is nil. | |
24 func UnwrapAll(err error) error { | |
25 for { | |
26 inner := Unwrap(err) | |
27 if inner == nil { | |
28 break | |
29 } | |
30 err = inner | |
31 } | |
32 return err | |
33 } | |
OLD | NEW |