sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

Better error system

Open tyt2y3 opened this issue 1 year ago • 14 comments

Continue #750

tyt2y3 avatar Aug 28 '22 05:08 tyt2y3

@mohs8421

tyt2y3 avatar Aug 28 '22 05:08 tyt2y3

Any updates on this?

Sculas avatar Sep 07 '22 00:09 Sculas

Hey @Sculas, we'll do a final review then merge it :)

billy1624 avatar Sep 07 '22 08:09 billy1624

Actually I strongly appreciate another pair of eyes to look at this

tyt2y3 avatar Sep 07 '22 16:09 tyt2y3

Would an error like UniqueConstraintError be out of scope for SeaORM? If not, maybe some other uncommon errors too? Just to make it easier for the user. If it's not out of scope I'm willing to make a PR for it.

Sculas avatar Sep 07 '22 16:09 Sculas

Would an error like UniqueConstraintError be out of scope for SeaORM? If not, maybe some other uncommon errors too? Just to make it easier for the user. If it's not out of scope I'm willing to make a PR for it.

This is needed very often when writing applications.

ikrivosheev avatar Sep 07 '22 16:09 ikrivosheev

This is needed very often when writing applications.

Yeah. I currently have some function that matches the error and checks if it's a unique constraint violation. It would be so much better if you could just check if it's a DbErr::UniqueConstraintViolation, for example.

Sculas avatar Sep 07 '22 16:09 Sculas

I think UniqueConstraintError can be a variant of RuntimeErr.

billy1624 avatar Sep 08 '22 04:09 billy1624

@Sculas that was my original intention with this discussion and the pull request in general. This pull request is now merely laying the foundation for what you suggest. There will be more after this one is done. See the discussion and my original PR. But yes effectively speaking it will help a lot to have all those typical database runtime errors be reflected by seaorm, like fk-related errors or deadlocks which might even be circumvented by a retry mechanism.

mohs8421 avatar Sep 08 '22 06:09 mohs8421

Thanks for the suggestion @ikrivosheev

tyt2y3 avatar Sep 13 '22 16:09 tyt2y3

I think UniqueConstraintError is only applicable to Exec, not Query ?

tyt2y3 avatar Sep 13 '22 16:09 tyt2y3

I think UniqueConstraintError is only applicable to Exec, not Query ?

That sqlx error that contains the unique constraint error is currently mapped to Query, so that would need to be changed.

My review in #750 mapped the error to Query: https://github.com/SeaQL/sea-orm/pull/750#pullrequestreview-1078933452 They should be mapped to Exec instead.

Sculas avatar Sep 13 '22 21:09 Sculas

shortly regarding the name of errors: I think in UniqueConstraintError the Error suffix seems to be noisy in my opinion, as it is already within the DbErr enum. I would rather rename it to UniqueConstraintViolation as that is more speaking.

mohs8421 avatar Sep 14 '22 05:09 mohs8421

I think UniqueConstraintError is only applicable to Exec, not Query ?

It should be applicable to Exec only. But I suspect update / insert operation with RETURNING is executed with query_one. So, the error might end up in DbErr::Query.

billy1624 avatar Sep 14 '22 07:09 billy1624

Hey, any updates on this PR?

Sculas avatar Sep 27 '22 12:09 Sculas

Thank you for your patience

tyt2y3 avatar Oct 06 '22 16:10 tyt2y3