| Index: common/errors/wrap.go
|
| diff --git a/common/errors/wrap.go b/common/errors/wrap.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..93b78db9a3450da5b739b2a6578b45ceb375fe3d
|
| --- /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
|
| +
|
| +// Wrapped indicates an error that wraps another error.
|
| +type Wrapped 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.(Wrapped); 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
|
| +}
|
|
|