Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose error code for PG backend #4290

Merged
merged 2 commits into from
Oct 1, 2024
Merged

Conversation

jrandolf
Copy link
Contributor

This allows for robust handling of PG errors that are not already enumerated.

@weiznich
Copy link
Member

Thanks for opening this PR. Could you provide some more details about which SQL Error codes you want to handle outside of diesel and why that's required.

Additionally: I fear we cannot merge the PR as it is as it contains a breaking change (adding a new required method to an public trait).

Finally: There should be at least one test for this.

@jrandolf
Copy link
Contributor Author

jrandolf commented Sep 30, 2024

I'd like to handle exclusion errors, but possibly others if they come up. I'd rather not file a PR for each case though, so it makes more sense IMO to just expose the code. After all, sql state is somewhat standardized AFAIU. Perhaps not the codes themselves, but the concept of a code itself.

I will add a test.

Would you like me to just add a default implementation to code?

@Ten0
Copy link
Member

Ten0 commented Sep 30, 2024

I'd like to handle exclusion errors, but possibly others if they come up. I'd rather not file a PR for each case though, so it makes more sense IMO to just expose the code

IMO adding those to DatabaseErrorKind will result in a more readable and less error-prone code when matching on those errors, and in addition it wouldn't be a breaking change, as documented on DatabaseErrorKind (which is also marked as #[non_exhaustive]).
Adding the 2 or 3 "Integrity Constraint Violations" that are still missing there would seem reasonable, and I would tend to imagine that that represents most of the "other cases that one may want to catch later on".

I'm not opposed to adding the method currently suggested by this PR but the above feels like a reasonable first step given the compromise that there is otherwise between backwards compatibility (previously mentioned breaking change) and correctness (any existing implementation of this trait is unlikely to be as correct as it should be if we add a default impl for this method).

diesel/src/result.rs Outdated Show resolved Hide resolved
@jrandolf
Copy link
Contributor Author

@Ten0 Alright, I've just added the remaining constraints to the enum. Do you folks want test for these errors or is this sufficient?

@jrandolf jrandolf requested a review from Ten0 September 30, 2024 23:43
Copy link
Member

@Ten0 Ten0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM apart from this

diesel/src/pg/connection/result.rs Outdated Show resolved Hide resolved
@weiznich weiznich added this pull request to the merge queue Oct 1, 2024
Merged via the queue into diesel-rs:master with commit dcc7241 Oct 1, 2024
48 checks passed
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.

3 participants