-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
tomlkit
0.12.5 : Encoder contract interferes with external TypeError
s raised in encoders
#355
Comments
Can you show me how the TypeError occurs? It seems like the encoder is not well implemented. Library and frameworks should be loose about input and strict about output. |
@frostming I think the OP's backtrace is sufficient to answer your question. Not well implemented is besides the point here: non-standard libraries should define their own exception type(s) if they assume they're the only one to raise them. The example is to show that. |
|
It could be a suboptimal design, more of Python‘s standard library suffers from that. (But You could enforce using a subclass of To illustrate your example, can you show how the custom encoder gets invoked? I don't see that in the example which makes it harder to comment on the appropriateness of the exception message. |
…peError`s raised in encoders Fixes #355 Signed-off-by: Frost Ming <[email protected]>
Okay, I am convinced.
The example was wrong, I've updated it |
…peError`s raised in encoders (#358) Fixes #355 Signed-off-by: Frost Ming <[email protected]>
Problem
register_encoder
expects encoder functions to raise aTypeError
when encoding fails.TypeError
s are an error class not specific totomlkit
, however, and this causes interference and unclear tracebacks.For example:
Solution
Change the API to use a
tomlkit
-specific and fine-grained, encoder-specific exception class.The text was updated successfully, but these errors were encountered: