9 // ErrRecordNotFound record not found error, happens when only haven't find any matched data when looking up with a struct, finding a slice won't return this error
10 ErrRecordNotFound = errors.New("record not found")
11 // ErrInvalidSQL invalid SQL error, happens when you passed invalid SQL
12 ErrInvalidSQL = errors.New("invalid SQL")
13 // ErrInvalidTransaction invalid transaction when you are trying to `Commit` or `Rollback`
14 ErrInvalidTransaction = errors.New("no valid transaction")
15 // ErrCantStartTransaction can't start transaction when you are trying to start one with `Begin`
16 ErrCantStartTransaction = errors.New("can't start transaction")
17 // ErrUnaddressable unaddressable value
18 ErrUnaddressable = errors.New("using unaddressable value")
21 // Errors contains all happened errors
24 // IsRecordNotFoundError returns current error has record not found error or not
25 func IsRecordNotFoundError(err error) bool {
26 if errs, ok := err.(Errors); ok {
27 for _, err := range errs {
28 if err == ErrRecordNotFound {
33 return err == ErrRecordNotFound
36 // GetErrors gets all happened errors
37 func (errs Errors) GetErrors() []error {
42 func (errs Errors) Add(newErrors ...error) Errors {
43 for _, err := range newErrors {
48 if errors, ok := err.(Errors); ok {
49 errs = errs.Add(errors...)
52 for _, e := range errs {
58 errs = append(errs, err)
65 // Error format happened errors
66 func (errs Errors) Error() string {
67 var errors = []string{}
68 for _, e := range errs {
69 errors = append(errors, e.Error())
71 return strings.Join(errors, "; ")