mirror of https://github.com/jackc/pgx.git
Add SeverityUnlocalized field to PgError / Notice
https://github.com/jackc/pgx/issues/1971pull/1982/head
parent
78b22c3d2f
commit
a3d9120636
|
@ -30,6 +30,7 @@ func Timeout(err error) bool {
|
||||||
// detailed field description.
|
// detailed field description.
|
||||||
type PgError struct {
|
type PgError struct {
|
||||||
Severity string
|
Severity string
|
||||||
|
SeverityUnlocalized string
|
||||||
Code string
|
Code string
|
||||||
Message string
|
Message string
|
||||||
Detail string
|
Detail string
|
||||||
|
|
|
@ -929,6 +929,7 @@ func (pgConn *PgConn) Deallocate(ctx context.Context, name string) error {
|
||||||
func ErrorResponseToPgError(msg *pgproto3.ErrorResponse) *PgError {
|
func ErrorResponseToPgError(msg *pgproto3.ErrorResponse) *PgError {
|
||||||
return &PgError{
|
return &PgError{
|
||||||
Severity: msg.Severity,
|
Severity: msg.Severity,
|
||||||
|
SeverityUnlocalized: msg.SeverityUnlocalized,
|
||||||
Code: string(msg.Code),
|
Code: string(msg.Code),
|
||||||
Message: string(msg.Message),
|
Message: string(msg.Message),
|
||||||
Detail: string(msg.Detail),
|
Detail: string(msg.Detail),
|
||||||
|
|
|
@ -1556,9 +1556,9 @@ func TestConnOnNotice(t *testing.T) {
|
||||||
config, err := pgconn.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
|
config, err := pgconn.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var msg string
|
var notice *pgconn.Notice
|
||||||
config.OnNotice = func(c *pgconn.PgConn, notice *pgconn.Notice) {
|
config.OnNotice = func(c *pgconn.PgConn, n *pgconn.Notice) {
|
||||||
msg = notice.Message
|
notice = n
|
||||||
}
|
}
|
||||||
config.RuntimeParams["client_min_messages"] = "notice" // Ensure we only get the message we expect.
|
config.RuntimeParams["client_min_messages"] = "notice" // Ensure we only get the message we expect.
|
||||||
|
|
||||||
|
@ -1576,7 +1576,8 @@ begin
|
||||||
end$$;`)
|
end$$;`)
|
||||||
err = multiResult.Close()
|
err = multiResult.Close()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "hello, world", msg)
|
assert.Equal(t, "NOTICE", notice.SeverityUnlocalized)
|
||||||
|
assert.Equal(t, "hello, world", notice.Message)
|
||||||
|
|
||||||
ensureConnValid(t, pgConn)
|
ensureConnValid(t, pgConn)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue