error.go 653 B

12345678910111213141516171819202122232425262728293031323334
  1. package errors
  2. import (
  3. oe "errors"
  4. "fmt"
  5. "runtime"
  6. )
  7. func New(text string) error {
  8. _, file, line, _ := runtime.Caller(1)
  9. return oe.New(fmt.Sprintf("%s at %s:%d", text, file, line))
  10. }
  11. func Wrap(err error) error {
  12. _, file, line, _ := runtime.Caller(1)
  13. return fmt.Errorf("at %s:%d\n%w", file, line, err)
  14. }
  15. func WrapWithMsg(err error, msg string) error {
  16. _, file, line, _ := runtime.Caller(1)
  17. return fmt.Errorf("%s at %s:%d\n%w", msg, file, line, err)
  18. }
  19. func Unwrap(err error) error {
  20. return oe.Unwrap(err)
  21. }
  22. func Is(err, target error) bool {
  23. return oe.Is(err, target)
  24. }
  25. func As(err error, target any) bool {
  26. return oe.As(err, target)
  27. }