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.
Raise with message helper
What does this add?
This PR adds a helper function that will allow a user to easily add custom messages to already existing Exceptions
Who is it for?
Developers who want to provide clearer messages for errors
Why is it needed?
I constantly see myself going through the same repeating patterns when writing better error logs for Exceptions, and this PR improves this frustration by writing a quick util for it
What parts of the API does this impact?
User-facing:
Adds a new
raise_with_msg
function that takes in an exception, a message, and a boolean of whether to append the new message to the original exception args (e.args
) or to override them completely with the new messageInternal structure:
None, however after this PR it will be propagated into fastai for the debugging errors/logs
Basic Usage Example(s):
Before:
After:
When would I use it, and when wouldn't I?
You'd use this specifically when the default error/exception might need to be changed, and putting the message in the base exception will not do. Such as when there are multiple triggers for the same exception, but depending on where it was called from their context could be slightly different
Does a similar feature exist? If so, why is this better?
No
cc @hamelsmu @jph00