You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Create specializations for common Database exceptions. #3282
When a database query exception occurs, a lot of knowledge is required to understand what common exceptions are good to handle when performing database calls.
Although there is good external documentation and guides around this, the framework has an opportunity to guide developers around which of these are to be expected from common operations.
Proposal
Introduce specializations for common database query exceptions that allow these to be explicitly cached in a try-catch statement.
Before specialization:
try {
awaitMyModel.db.inserRow(session, userInfo);
} onDatabaseQueryExceptioncatch e {
if (e.code !=PgErrorCode.foreignKeViolation) rethrow; // Note that the rethrow here is important otherwise all DatabaseQueryExceptions would be silenced.// Handling of already existing user during insert...
}
After specialization:
try {
awaitMyModel.db.inserRow(session, userInfo);
} onUniqueViolationQueryException {
// Handling of already existing user during insert...
}
This, combined with an added description for all database operation methods informing the user about the exception structure, would make it easy to understand what exception handling is required.
Use Case
As suggested in the proposal, handling multiple entries into a table with a unique index would be greatly alleviated.
Alternatives
N/A
Additional context
No response
How experienced are you with this library?
Expert - Experienced and comfortable with using this library in complex projects
Activity