jackc/pgx: error handling

1,029 views
Skip to first unread message

Larry Rosenman

unread,
Oct 18, 2021, 11:21:29 PM10/18/21
to golang-nuts

I'm translating an OLD program from lib/pq to pgx, but when I copy the "Error Handling" code, I get:
./ambientProgram.go:164:16: db.PgError undefined (type *pgx.Conn has no field or method PgError) ./ambientProgram.go:210:18: db.PgError undefined (type *pgx.Conn has no field or method PgError)

I get the connection by:
db, err := pgx.Connect(context.Background(), connStr)

and pass it to:
func populatedb(macaddr string, db *pgx.Conn, endtime time.Time)

How do I get to the error stuff?

Thanks!

ref: https://github.com/jackc/pgx/issues/1102
https://github.com/jackc/pgx/wiki/Error-Handling

Larry Rosenman

unread,
Oct 18, 2021, 11:23:04 PM10/18/21
to golan...@googlegroups.com
I found my error with some help on a slack channel.  Thanks, though.

Kurtis Rader

unread,
Oct 18, 2021, 11:25:17 PM10/18/21
to Larry Rosenman, golang-nuts
For future readers who stumble upon this thread it would be nice if you explained the problem and solution in more detail.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/41d31af8-d053-40cb-8957-8112ce935ee3n%40googlegroups.com.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Larry Rosenman

unread,
Oct 19, 2021, 1:46:40 AM10/19/21
to Kurtis Rader, golang-nuts
I had a misunderstanding of what imports needed to be included, and a fundamental misunderstanding of type vs field.

I added an import of:
github.com/jackc/pgconn

and changed the declaration to
var pgError *pgconn.PgError

and now I'm fine. 

--
Larry Rosenman                     http://www.lerctr.org/~ler
Phone: +1 214-642-9640 (c)     E-Mail: larr...@gmail.com
US Mail: 5708 Sabbia Dr, Round Rock, TX 78665-2106
Reply all
Reply to author
Forward
0 new messages