This repository has been archived by the owner on Dec 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Go 1.13 error chains in
Cause
(#215)
- Loading branch information
Showing
4 changed files
with
85 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters