summaryrefslogtreecommitdiff
path: root/vendor/github.com/pkg/errors/cause.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/pkg/errors/cause.go')
-rw-r--r--vendor/github.com/pkg/errors/cause.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/github.com/pkg/errors/cause.go b/vendor/github.com/pkg/errors/cause.go
new file mode 100644
index 000000000..566f88bb0
--- /dev/null
+++ b/vendor/github.com/pkg/errors/cause.go
@@ -0,0 +1,29 @@
+// +build !go1.13
+
+package errors
+
+// Cause recursively unwraps an error chain and returns the underlying cause of
+// the error, if possible. An error value has a cause if it implements the
+// following interface:
+//
+// type causer interface {
+// Cause() error
+// }
+//
+// If the error does not implement Cause, the original error will
+// be returned. If the error is nil, nil will be returned without further
+// investigation.
+func Cause(err error) error {
+ type causer interface {
+ Cause() error
+ }
+
+ for err != nil {
+ cause, ok := err.(causer)
+ if !ok {
+ break
+ }
+ err = cause.Cause()
+ }
+ return err
+}