Skip to content

refactor: Rework database exception hierarchy - #5571

Merged
Crazelu merged 21 commits into
serverpod:mainfrom
Crazelu:refactor/database-exception-hierarchy
Aug 21, 2026
Merged

Crazelu merged 21 commits into
serverpod:mainfrom
Crazelu:refactor/database-exception-hierarchy

Conversation

@Crazelu

@Crazelu Crazelu commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

This PR allows DatabaseException (and DatabaseQueryException) to be extendable from outside the Serverpod library. Specialized exceptions for insert, update and delete are replaced by the generic DatabaseException.

Stacked on #5560
Closes #3283

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

Breaking changes

  • The specialized DatabaseInsertRowException, DatabaseUpdateRowException and DatabaseDeleteRowException implementations have been replaced with DatabaseException.

@Crazelu
Crazelu marked this pull request as ready for review August 10, 2026 20:47
@Crazelu
Crazelu requested a review from a team August 10, 2026 20:47

@FXschwartz FXschwartz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just a couple of comments and one general question:

The breaking changes section lists insert/update/delete, but DatabaseUpsertRowException is removed too, would it be worth adding since it was also part of the public API?

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Few more suggestions for discussion to make the exception more specific on some paths.

@Crazelu
Crazelu force-pushed the refactor/database-exception-hierarchy branch 2 times, most recently from aa413ce to f98614d Compare August 19, 2026 12:19

@FXschwartz FXschwartz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

All my feedback has been addressed! Approved pending Marcelo's comments.

@Crazelu
Crazelu force-pushed the refactor/database-exception-hierarchy branch from f98614d to 48b3942 Compare August 19, 2026 20:07
@Crazelu

Crazelu commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

@marcelomendoncasoares I've introduced DatabaseUniqueViolationException and DatabaseForeignKey ViolationException in 48b3942 for the most relevant error codes.

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Only a few more suggestions and we're good to go.

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! 🚀

@Crazelu
Crazelu merged commit 43c5075 into serverpod:main Aug 21, 2026
480 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 21, 2026
@marcelomendoncasoares marcelomendoncasoares linked an issue Oct 26, 2026 that may be closed by this pull request
1 task
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rework exception hierarchy in Serverpod. Create specializations for common Database exceptions.

3 participants