Add context to RecordNotSaved/RecordNotDestroyed error messages #452
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.
Hello,
I struggled to display error messages from Granite when testing my code. The
RecordNotSaved
andRecordNotDestroyed
messages are too generic and do not provide any clue about what is going on when an error is triggered when callingsave!
ordestroy!
.We could, indeed, call
save
instead ofsave!
and collect those error messages. But it would be cumbersome and need to add boilerplate everywhere. IMHO, it is usually simpler (and preferred) to manage exceptions.So, I've added the message of the first error in the model to ease the feedback loop and have some understandings on the error directly instead of having to add code around to know what is the real issue.
Please let me know if you disagree with this and if you would see a better implementation.
Cheers!