Skip to content

Commit f473a89

Browse files
committed
added pqconn.GetRaisedException
1 parent d6a7ab9 commit f473a89

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

pqconn/errors.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,23 @@ func IsExclusionViolation(err error) bool {
8080

8181
// Class P0 — PL/pgSQL Error
8282

83-
func IsPlpgsqlError(err error) bool {
83+
func IsPLPGSQLError(err error) bool {
8484
var e *pq.Error
85-
return errors.As(err, &e) && e.Code == "P0000" // plpgsql_error
85+
return errors.As(err, &e) && e.Code == "P0000"
8686
}
8787

88-
func IsRaiseException(err error) bool {
88+
func IsRaisedException(err error) bool {
8989
var e *pq.Error
90-
return errors.As(err, &e) && e.Code == "P0001" // raise_exception
90+
return errors.As(err, &e) && e.Code == "P0001"
91+
}
92+
93+
// GetRaisedException returns the message
94+
// of an PL/pgSQL exception or and empty string
95+
// if the error is nil or not an exception.
96+
func GetRaisedException(err error) string {
97+
var e *pq.Error
98+
if errors.As(err, &e) && e.Code == "P0001" {
99+
return e.Message
100+
}
101+
return ""
91102
}

0 commit comments

Comments
 (0)