-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added custom exception (inheriting from KeyError) when deserialization fails #207
base: feat/207
Are you sure you want to change the base?
Conversation
Hmm, why did the second try get cancelled? I think it should have passed the linter this time |
177ef80
to
64cd7b1
Compare
64cd7b1
to
7031df5
Compare
dataclasses_json/errors.py
Outdated
@@ -0,0 +1,3 @@ | |||
class DataclassSerializationException(KeyError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps class DataclassJsonError(Exception)
instead, to make it clear it's coming from this package, not dataclasses itself -- user-defined exceptions typically inherit from Exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's weird not inheriting from Exception
but I wanted to inherit from KeyError
so that any client code that might have caught the old exception would still catch the new one.
I feel like inheriting from Exception
would be a bit of a breaking change .. fine by me, but not sure if everyone would feel that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha, that's a good thought and thanks for clarifying
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the contribution! better errors is always great, and i appreciate the contribution a lot
see #206 (comment) |
…lassJson). Added base exception, but currently not inheriting from that.
I have added a quickly put together patch that helps with issue #206, it will raise a custom exception (that inherits from KeyError from clients that were catching that exception) and reports the actual object that failed and the field it failed for.