2
0

PG error type is *pgconn.PgError

This commit is contained in:
Jack Christensen
2018-12-31 17:46:56 -06:00
parent bcc3da490c
commit 49c9674102
2 changed files with 7 additions and 7 deletions
+5 -5
View File
@@ -45,7 +45,7 @@ type PgError struct {
Routine string
}
func (pe PgError) Error() string {
func (pe *PgError) Error() string {
return pe.Severity + ": " + pe.Message + " (SQLSTATE " + pe.Code + ")"
}
@@ -118,7 +118,7 @@ func ConnectConfig(ctx context.Context, config *Config) (pgConn *PgConn, err err
pgConn, err = connect(ctx, config, fc)
if err == nil {
return pgConn, nil
} else if err, ok := err.(PgError); ok {
} else if err, ok := err.(*PgError); ok {
return nil, err
}
}
@@ -199,7 +199,7 @@ func connect(ctx context.Context, config *Config, fallbackConfig *FallbackConfig
// handled by ReceiveMessage
case *pgproto3.ErrorResponse:
pgConn.NetConn.Close()
return nil, PgError{
return nil, &PgError{
Severity: msg.Severity,
Code: msg.Code,
Message: msg.Message,
@@ -654,8 +654,8 @@ func (pgConn *PgConn) Exec(ctx context.Context, sql string) (*PgResult, error) {
return result, nil
}
func errorResponseToPgError(msg *pgproto3.ErrorResponse) PgError {
return PgError{
func errorResponseToPgError(msg *pgproto3.ErrorResponse) *PgError {
return &PgError{
Severity: msg.Severity,
Code: msg.Code,
Message: msg.Message,
+2 -2
View File
@@ -269,7 +269,7 @@ func TestConnExecMultipleQueriesError(t *testing.T) {
result, err := pgConn.Exec(context.Background(), "select 1; select 1/0; select 1")
require.NotNil(t, err)
require.Nil(t, result)
if pgErr, ok := err.(pgconn.PgError); ok {
if pgErr, ok := err.(*pgconn.PgError); ok {
assert.Equal(t, "22012", pgErr.Code)
} else {
t.Errorf("unexpected error: %v", err)
@@ -331,7 +331,7 @@ func TestConnCancelQuery(t *testing.T) {
require.Nil(t, err)
_, err = pgConn.GetResult(context.Background()).Close()
if err, ok := err.(pgconn.PgError); ok {
if err, ok := err.(*pgconn.PgError); ok {
assert.Equal(t, "57014", err.Code)
} else {
t.Errorf("expected pgconn.PgError got %v", err)