-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
40 lines (33 loc) · 1.08 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package pgxscan
import (
"fmt"
"strings"
)
// ErrQueryColumnsTagsMismtach is returned when not all struct tags count does not match query column count
// This is a non-fatal error and can be ignored if the above is by design or planned
// This however acts as a fail-safe to avoid missing columns inside your select calls
var ErrQueryColumnsTagsMismtach = fmt.Errorf("query returned less columns than DB tags on struct")
type ErrUnexportedProperty struct {
PropertyName string
}
func (err ErrUnexportedProperty) Error() string {
return fmt.Sprintf("unable to access unexported field '%s'", err.PropertyName)
}
type ErrQueryReturnedExtraColumns struct {
ValueType string
Columns []string
}
func (err ErrQueryReturnedExtraColumns) Error() string {
columnOptionalPlural := "column"
tagOptionalPlural := "tag"
if len(err.Columns) > 1 {
columnOptionalPlural = "columns"
tagOptionalPlural = "tags"
}
return fmt.Sprintf("query returned %s %s the supplied struct of type %T does not contain these %s",
columnOptionalPlural,
strings.Join(err.Columns, ","),
nil,
tagOptionalPlural,
)
}