-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: don't test error identities using reference equality
Prior to this patch, the SQL code was expecting to identify errors by addess, ie. something like: ```go // at global scope var errSomething = errors.New(...) // somewhere in the code if err == errSomething { ... } ``` This approach was flawed in that errors can be wrapped (`errors.Wrap`, `errors.WithMessage`) or flattened (`pgerror.Wrap`) or sent over the wire. To make the code more robust, this patch introduces a new API `pgerror.WithMarker()` which instantiates errors with a unique marker. The marker is guaranteed to be preserved through `errors.Wrap` and `pgerror.Wrap` calls. It can be tested with `pgerror.IsMarkedError()`. The patch then updates the various points in the SQL code where errors were tested in that way, to use the new API. (In some places some attempt is made to "work around" with a string comparison on the message instead, but that's arguably even worse for reasons left as an exercise to the reader. This should also be fixed, but that fix is out of scope here.) Release note: None
- Loading branch information
Showing
22 changed files
with
443 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.