go113.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // +build go1.13
  2. package errors
  3. import (
  4. stderrors "errors"
  5. )
  6. // Is reports whether any error in err's chain matches target.
  7. //
  8. // The chain consists of err itself followed by the sequence of errors obtained by
  9. // repeatedly calling Unwrap.
  10. //
  11. // An error is considered to match a target if it is equal to that target or if
  12. // it implements a method Is(error) bool such that Is(target) returns true.
  13. func Is(err, target error) bool { return stderrors.Is(err, target) }
  14. // As finds the first error in err's chain that matches target, and if so, sets
  15. // target to that error value and returns true.
  16. //
  17. // The chain consists of err itself followed by the sequence of errors obtained by
  18. // repeatedly calling Unwrap.
  19. //
  20. // An error matches target if the error's concrete value is assignable to the value
  21. // pointed to by target, or if the error has a method As(interface{}) bool such that
  22. // As(target) returns true. In the latter case, the As method is responsible for
  23. // setting target.
  24. //
  25. // As will panic if target is not a non-nil pointer to either a type that implements
  26. // error, or to any interface type. As returns false if err is nil.
  27. func As(err error, target interface{}) bool { return stderrors.As(err, target) }
  28. // Unwrap returns the result of calling the Unwrap method on err, if err's
  29. // type contains an Unwrap method returning error.
  30. // Otherwise, Unwrap returns nil.
  31. func Unwrap(err error) error {
  32. return stderrors.Unwrap(err)
  33. }