From a5f082fa03f4f0fd3f11e01d937ba14b2c1a19db Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Mon, 15 Sep 2014 14:52:32 -0500 Subject: [PATCH] Extract more error information --- conn.go | 14 ++++++++++++++ messages.go | 16 +++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/conn.go b/conn.go index ee225c91..6a9c0a01 100644 --- a/conn.go +++ b/conn.go @@ -676,6 +676,20 @@ func (c *Conn) rxErrorResponse(r *msgReader) (err PgError) { err.Code = r.readCString() case 'M': err.Message = r.readCString() + case 'D': + err.Detail = r.readCString() + case 'H': + err.Hint = r.readCString() + case 's': + err.SchemaName = r.readCString() + case 't': + err.TableName = r.readCString() + case 'c': + err.ColumnName = r.readCString() + case 'd': + err.DataTypeName = r.readCString() + case 'n': + err.ConstraintName = r.readCString() case 0: // End of error message if err.Severity == "FATAL" { c.die(err) diff --git a/messages.go b/messages.go index 45cc92fc..fc8de65f 100644 --- a/messages.go +++ b/messages.go @@ -60,10 +60,20 @@ type FieldDescription struct { FormatCode int16 } +// PgError represents an error reported by the PostgreSQL server. See +// http://www.postgresql.org/docs/9.3/static/protocol-error-fields.html for +// detailed field description. type PgError struct { - Severity string - Code string - Message string + Severity string + Code string + Message string + Detail string + Hint string + SchemaName string + TableName string + ColumnName string + DataTypeName string + ConstraintName string } func (self PgError) Error() string {