pgerror: use a different type for pgcodes #49694
Labels
A-sql-pgwire
pgwire protocol issues.
C-enhancement
Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
E-easy
Easy issue to tackle, requires little or no CockroachDB experience
good first issue
tldr: we want to change the API signature of
pgerror.Newf
andpgerror.Wrapf
and possibly other things that accept a pg error code as argument.Background
As found in #49660, there was a mistake in the code
The second argument should be the pgcode, not the error string.
The Go type system does not catch this - the interface of
Wrapf
is(error, string, string, ...interface{})
It's too easy to mistakenly forget the pgcode in there.
We can't use
type Code string
ortype Code = string
because that doesn't block the error above.Proposal
We can do this in package
pgcode
:then change
pgerror.Wrapf
to take(error, pgcode.Code, string, ...interface{})
All the pre-defined code can be generated to use that struct instead of a simple string (the're a generation script already, so we can automate the conversion).
suggested by @dt @tbg
The text was updated successfully, but these errors were encountered: