-
Notifications
You must be signed in to change notification settings - Fork 624
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
Unable to catch MissingFieldException #1266
Comments
Could you please elaborate on what exactly are you trying to achieve? E.g. provide a snippet of code and/or a use-case. |
For me it's just to fulfill an API contract and return a better error, so if you don't want to commit to this in the public API my hack works fine for me. |
Well, it's not really about us wanting it or not, but about the rationale behind the decision. In general, we're trying to keep public API as small as possible, but still concise and pragmatic. So before making it public, we should know why it can be useful.
Could you please elaborate on why you can't catch plain |
I second this and also not having the field name as an attribute of exception. |
@qwwdfsad ping |
For example in 1.1.0 it will be not the name, but names: https://github.com/Kotlin/kotlinx.serialization/blob/dev/core/commonMain/src/kotlinx/serialization/SerializationException.kt#L70 And it's nice for us to have an ability to freely change this API without preserving backwards compatibility. Could you please elaborate on what's wrong with the default error message and how can we improve it? |
for example internationalisation |
well as in my example, when using serialization for http requests, I want to tell client why is his input bad, what's wrong with it, and which field is responsible |
Because we can only catch SerializationException, it is difficult to programmatically know if it's an issue due to improper JSON formatting, missing fields, or extraneous fields. We could parse the string and use that to determine which issue we're facing, but that is obviously a lot less safe than relying on a type. Uses for being able to differentiate based on type instead of just letting the error message through include: different logging requirements depending on the organization (e.g. the error message may contain sensitive information), custom error codes for clients, custom error messages for clients, error reporting in an event-based architecture, routing to an appropriate error-correction handler, etc. There are many possibilities. |
Sorry, not sure if it is related to the topic or should I create a separate issue. But why most of the exceptions are internal? |
@mskonovalov well, that's what this ticket is all about. But my hope keeps within limits. JetBrains has too many projects they're working on simultaneously. |
I'm working on that along with #1875 |
What is your use-case and why do you need this feature?
I'd like to programmatically catch MissingFieldExceptions without having to resort to reading the stacktrace in order to check.
Describe the solution you'd like
Make MissingFieldException public.
The text was updated successfully, but these errors were encountered: