github.com/shoshinnikita/budget-manager@v0.7.1-0.20220131195411-8c46ff1c6778/internal/pkg/errors/errors.go (about) 1 // Package errors provides functions similar to functions in github.com/pkg/errors 2 // but uses fmt.Errorf function to wrap errors 3 package errors 4 5 import ( 6 "errors" 7 "fmt" 8 ) 9 10 func New(text string) error { 11 return errors.New(text) 12 } 13 14 func Errorf(format string, args ...interface{}) error { 15 return fmt.Errorf(format, args...) 16 } 17 18 // Wrap wraps an error using fmt.Errorf function. If err is nil, Wrap returns nil. 19 func Wrap(err error, msg string) error { 20 if err == nil { 21 return nil 22 } 23 return fmt.Errorf("%s: %w", msg, err) 24 } 25 26 // Wrapf wraps an error using fmt.Errorf function. If err is nil, Wrapf returns nil. 27 func Wrapf(err error, format string, args ...interface{}) error { 28 if err == nil { 29 return nil 30 } 31 return Wrap(err, fmt.Sprintf(format, args...)) 32 } 33 34 func Is(err, target error) bool { 35 return errors.Is(err, target) 36 }