Skip to content

Commit d6a7ab9

Browse files
committed
ErrNullValueNotAllowed and ErrRaisedException
1 parent db6c969 commit d6a7ab9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

errors.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,18 @@ const (
5353
// that are are only allowed within DB transactions
5454
// when the DB connection is not a transaction.
5555
ErrNotWithinTransaction sentinelError = "not within a transaction"
56+
57+
ErrNullValueNotAllowed sentinelError = "null value not allowed"
5658
)
5759

60+
type ErrRaisedException struct {
61+
Message string
62+
}
63+
64+
func (e ErrRaisedException) Error() string {
65+
return "raised exception: " + e.Message
66+
}
67+
5868
type ErrIntegrityConstraintViolation struct {
5969
Constraint string
6070
}

pqconn/errors.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ func WrapKnownErrors(err error) error {
1717
var e *pq.Error
1818
if errors.As(err, &e) {
1919
switch e.Code {
20+
case "22004":
21+
return errors.Join(sqldb.ErrNullValueNotAllowed, err)
2022
case "23000":
2123
return errors.Join(sqldb.ErrIntegrityConstraintViolation{Constraint: e.Constraint}, err)
2224
case "23001":
@@ -31,6 +33,8 @@ func WrapKnownErrors(err error) error {
3133
return errors.Join(sqldb.ErrCheckViolation{Constraint: e.Constraint}, err)
3234
case "23P01":
3335
return errors.Join(sqldb.ErrExclusionViolation{Constraint: e.Constraint}, err)
36+
case "P0001":
37+
return errors.Join(sqldb.ErrRaisedException{Message: e.Message}, err)
3438
}
3539
}
3640
return err

0 commit comments

Comments
 (0)