go113.go 1.4 KB

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