blob: 1c3c713aa5262ad391c5ecb9c4ef24fa0a401bf4 [file] [log] [blame]
// Package errors implements functions to manipulate errors.
package errors
type errorString string
func (e errorString) Error() string {
return string(e)
}
// New returns an error that formats as the given text.
func New(text string) error {
return errorString(text)
}
// Cause returns the underlying cause of the error, if possible.
// An error value has a cause if it implements the following
// method:
//
// 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 {
if err == nil {
return nil
}
if err, ok := err.(interface {
Cause() error
}); ok {
return err.Cause()
}
return err
}