Skip to content

fix: Support typed database exceptions. - #3047

Merged
SandPod merged 12 commits into
serverpod:mainfrom
SandPod:support-typed-database-exceptions
Dec 12, 2024
Merged

SandPod merged 12 commits into
serverpod:mainfrom
SandPod:support-typed-database-exceptions

Conversation

@SandPod

@SandPod SandPod commented Dec 11, 2024 •

Copy link
Copy Markdown
Contributor

Introduces a new database exception type called DatabaseQueryException that contains information related to an exception that occurred during a database query.

The fields exposed through the DatabaseQueryException class have been minimized to contain what is most relevant to the user.

Please provide feedback if any important field has been left out.

The code field, which is probably what most developers will add code to parse, would have been nice to have typed. But since codes are not shared between different database types, the field is simply a nullable String.

This PR supersedes the original PR introduced here: #2546

Database exception abstract interfaces

New interfaces have been added that allow the framework to extend the interfaces in a backward-compatible way.

By using abstract interface class we reserve the right to extend the interface in the future and prevent code outside of the library to implement it.

An implementation of the interface has been added to the Postgres adapter. This continues to set the foundation for allowing other adapters in the future.

Additional fixes

Where applicable, all legacy tests were converted to be more precise in their type checking.

The last commit also contains a minor refactor to flatten out the if statements when catching exceptions in a database query.

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.

If you need help, consider asking for advice on the discussion board.

Breaking changes

None - the intention behind these changes is to be implemented in a backwards-compatible way.
New subtypes in the adapter have been added, but these should not interfere with logic that catches current exceptions.

@SandPod
SandPod force-pushed the support-typed-database-exceptions branch from 6fce9ef to 8520c46 Compare December 11, 2024 12:11
@SandPod
SandPod force-pushed the support-typed-database-exceptions branch from 8520c46 to ab8c80d Compare December 11, 2024 12:26
@SandPod
SandPod marked this pull request as ready for review December 11, 2024 13:08
@SandPod

SandPod commented Dec 11, 2024

Copy link
Copy Markdown
Contributor Author

@lukehutch - Please have a look at this to ensure everything you need is included.

@SandPod
SandPod requested a review from Isakdl December 11, 2024 13:34

@hampuslavin hampuslavin left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good! 🏎️ Just some small Qs

@SandPod
SandPod force-pushed the support-typed-database-exceptions branch from 8d75009 to 2757f9a Compare December 11, 2024 16:30

@christerswahn christerswahn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a really great "maturity" improvement! :) Left some comments and discussion point!

@lukehutch

Copy link
Copy Markdown
Contributor

@lukehutch - Please have a look at this to ensure everything you need is included.

LGTM, other than the open comments.

@hampuslavin hampuslavin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good on my end 👍

@christerswahn christerswahn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@SandPod
SandPod merged commit 3954117 into serverpod:main Dec 12, 2024
@SandPod
SandPod deleted the support-typed-database-exceptions branch December 12, 2024 10:05
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 12, 2024
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.

4 participants