-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: better database errors #2109
feat: better database errors #2109
Conversation
This looks brilliant to me. |
@saiintbrisson current development is on the |
Sure! Was waiting until the refac was over, will do! |
46f343c
to
0b94f50
Compare
15d5683
to
2c9415c
Compare
@abonander seems like we are good to go. I've deleted the MSSQL error implementation, but I'm wondering where I should put it, will the "pro" crate be available soon? EDIT: Important note: this PR fixes the |
You can just delete the MSSQL stuff, we'll be redoing that from scratch anyway.
|
2c9415c
to
3df5653
Compare
Right! Dropped the MSSQL commit @abonander.
|
I'll delete them, they're just dead code.
|
@saiintbrisson sadly You should be able to just insert a dereference, e.g. |
4da070b
to
749a5b2
Compare
@abonander Makes sense, I was expecting this to happen, and it did with sqlite, but |
@abonander MySQL has this weird functionality where CHECK constraints didn't exist before version 8.0, and the 5.7 server just "ignored it", we can't run tests for this version or any MariaDB. I'm not sure how to proceed, as the test isn't aware of the server version it's connecting to, any ideas? |
I believe we do send As for MySQL, we've used
It looks like 5.7 is slowly getting EOL'd as it's not supported on newer operating systems: https://www.mysql.com/support/supportedplatforms/database.html I'll be glad when we can drop it entirely cause it's kinda been a pain. |
749a5b2
to
8f64a53
Compare
8f64a53
to
8ac8749
Compare
@abonander I've re-ran all the tests locally and they seem to be working fine |
* feat(core): create error kind enum * feat(core): add error kind for postgres * feat(core): add error kind for sqlite * feat(core): add error kind for mysql * test(postgres): add error tests * test(sqlite): add error tests * test(mysql): add error tests * fix(tests): fix tests rebasing * refac(errors): add `ErrorKind::Other` variant
* feat(core): create error kind enum * feat(core): add error kind for postgres * feat(core): add error kind for sqlite * feat(core): add error kind for mysql * test(postgres): add error tests * test(sqlite): add error tests * test(mysql): add error tests * fix(tests): fix tests rebasing * refac(errors): add `ErrorKind::Other` variant
* feat(core): create error kind enum * feat(core): add error kind for postgres * feat(core): add error kind for sqlite * feat(core): add error kind for mysql * test(postgres): add error tests * test(sqlite): add error tests * test(mysql): add error tests * fix(tests): fix tests rebasing * refac(errors): add `ErrorKind::Other` variant
In light of problems I faced when error handling a back-end agnostic code, I've came up with an interface that lets the user figure out what kind of error the database returned, which fixes #2102.
The new
DatabaseError::kind(&self)
function tries to match the error code with a known kind, taking into account the back-end specific ways it might be returned. Four error kinds are supported for now: unique, foreign key, not null, and check violations.SQLite and Postgres are pretty straight forward, MySQL has multiple codes for each kind of violation, but MSSQL has a funny way of reporting checks and foreign key violations, it uses the same error code and differentiates the two in the message.
I've performed tests and all four kinds are supported for all back-ends currently supported, including check and foreign key for MSSQL.