Skip to content

Conversation

@arp242
Copy link
Collaborator

@arp242 arp242 commented Jan 13, 2026

This rewrites the error handling from panics to error returns.

The special handling to return driver.ErrBadConn is now in conn.handleError(), Something like this:

func (cn *conn) begin(mode string) (_ driver.Tx, err error) {
	defer cn.errRecover(&err)

	cn.checkIsInTransaction(false)
	[..]
}

Can now be rewritten to:

func (cn *conn) begin(mode string) (driver.Tx, error) {
	err := cn.checkIsInTransaction(false)
	if err != nil {
			return cn.handleError(err)
	}
	[..]
}

Which is not entirely ideal as calls to cn.handleError() need to be repeated, but it's fairly safe against regressions and rewriting things to handle these errors closer to the source can be done later.

PR is rather larger than I would like, but if you change it in one place you kind of need to change it everywhere.

Something like this:

	func (cn *conn) begin(mode string) (_ driver.Tx, err error) {
		defer cn.errRecover(&err)

		cn.checkIsInTransaction(false)
		[..]
	}

Can now be rewritten to:

	func (cn *conn) begin(mode string) (driver.Tx, error) {
		err := cn.checkIsInTransaction(false)
		if err != nil {
			return cn.handleError(err)
		}
		[..]
	}

Which is still not entirely ideal as calls to cn.handleError() need to
be repeated, but it's a good first step towards removing the panics, and
fairly safe against regressions.

errRecover() is rewritten to use this. I commented out the branches to
make sure tests fail (they do).
We want to ignore the error from these in cases where we're handling an
ErrorReponse, as we want to return the first error, which is almost
always the most useful one.
Update the list of unsupported environment variables and return an error
instead of panicking.
Remove most panics. The only ones remaining are in writeBuf when the
messages are too long (added in #1161). I think that's probably okay:
normal operations should never hit this.
@arp242 arp242 merged commit cda033a into master Jan 13, 2026
12 checks passed
@arp242 arp242 deleted the unpanic branch January 13, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants