Always throw exceptions rather than sometimes returning false #24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This will require a closer look, but I've been using these changes for a while with success.
Reasoning:
In most situations a problem with a query resulted in picodb's SQLException propagating out making for easy handling.
Here's the source of the exception in picodb for reference:
However in some situations, this exception is caught in picomapper and instead false is returned. This makes handling errors more difficult. The most common situation I encountered this, was when I had a bug and was attempting to update an aggregate with new duplicate child records. It would attempt to insert a duplicate child and that resulting exception would be caught and false would be returned. I was confused why my request was succeeding but my record wasn't updating. After diving in I figured out why, and thus this PR 😅
before:
after:
I've also opted to simply remove the returning false. Such as this example:
In the above example false is never returned, as the SQLException from picodb is thrown already. So I've simply replaced it with:
I've also escalated to exception any errors in the picomapper library that previously returned false, for example:
before:
after:
Maybe these should use a specific exception class from picomapper, I'm happy to add that if you have thoughts. I'd just kept it simple for now.