mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-09-20 07:29:50 +00:00
30 lines
630 B
Go
30 lines
630 B
Go
|
// +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
|
||
|
}
|