-
-
Notifications
You must be signed in to change notification settings - Fork 521
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
Better error system #1002
Better error system #1002
Conversation
* feat: Introducing feature "sqlx-error" Purpose of this feature is to not convert errors given from sqlx into strings to ease further analysis of the error and react to it accordingly. This implementation uses a feature switch and an additional error kind to avoid interfering with existing implementations without this feature enabled. See discussion #709 * fix: Align feature "sqlx-error" with merged Migration error kind Due to the merge, an other error kind had been introduced and the DbErr became Eq and Clone, however Eq cannot easily be derived from, so I went back to PartialEq, and since the sqlx error does not implement clone, this was converted into an Arc, to allow cloning of the new kind too. * fix: Repairing failing jobs Several jobs had failed as I missed to correct the return values of a few methods in transaction.rs and had a wrong understanding of map_err at that point. * feat: realigning with latest changes in sea-orm, different approach Instead of the former approach to introduce a new error kind, now the existing error types get extended, for now only Exec and Query, because these are the most relevant for the requirement context. Afterwards it might still be possible to add some further detail information. See discussion #709 * Update src/driver/sqlx_mysql.rs Integrating fixes done by @Sculas Co-authored-by: Sculas <[email protected]> * Update src/driver/sqlx_postgres.rs Integrating fixes done by @Sculas Co-authored-by: Sculas <[email protected]> * Update src/driver/sqlx_sqlite.rs Integrating fixes done by @Sculas Co-authored-by: Sculas <[email protected]> * feat: reworking feature with thiserror Following the latest suggestions I changed the implementation to utilize `thiserror`. Now there are more error kinds to be able to see the different kinds directly in src/error.rs To ensure the behaviour is as expected, I also introduce a further test, which checks for a uniqueness failure. Co-authored-by: Sculas <[email protected]>
sea-orm-macros/src/derives/column.rs
Outdated
let entity_name = data_enum | ||
.variants | ||
.first() | ||
.map(|column| { | ||
let column_iden = column.ident.clone(); | ||
quote!( | ||
#ident::#column_iden.entity_name().to_string() | ||
) | ||
}) | ||
.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @tyt2y3, yeah, this isn't possible considering we can DeriveColumn
on Enum that is not necessarily a Entity::Column
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed some typos and consistency in the error messages.
Co-authored-by: Sculas <[email protected]>
Co-authored-by: Sculas <[email protected]>
Co-authored-by: Sculas <[email protected]>
Co-authored-by: Sculas <[email protected]>
Any updates on this? |
Hey @Sculas, we'll do a final review then merge it :) |
Actually I strongly appreciate another pair of eyes to look at this |
Would an error like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find anything out of the ordinary, so LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small comment
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 |
I think |
@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. |
Thanks for the suggestion @ikrivosheev |
I think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tyt2y3 LGTM! I think we can create: UniqueConstraintError
in other PR.
That sqlx error that contains the unique constraint error is currently mapped to My review in #750 mapped the error to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I agree with ikrivosheev.
shortly regarding the name of errors: |
It should be applicable to |
Hey, any updates on this PR? |
Thank you for your patience |
* What's new in SeaORM 0.10.1 * Edit * Error handling (SeaQL/sea-orm#1002) * Support array datatype for Postgres (SeaQL/sea-orm#1132) * generate index file as `lib.rs` instead of `mod.rs` (SeaQL/sea-orm#953) * Running migration on any Postgres schema (SeaQL/sea-orm#1056) * More connection options (SeaQL/sea-orm#897, SeaQL/sea-orm#1056) * Implements `TryFrom<ActiveModel>` for `Model` (SeaQL/sea-orm#990) * Delete 2022-10-28-whats-new-in-0.10.1.md Co-authored-by: Chris Tsang <[email protected]>
Continue #750