Skip to content
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

Add field name to error when failing to parse a field of type Message #402

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

github-vincent-baret
Copy link

@github-vincent-baret github-vincent-baret commented Jul 20, 2023

We are missing a way to understand what is failing when converting json to proto. This PR updates the error with the proto field name for the field that cannot be parsed, and the descriptor full name of the message type that is expected.

@github-vincent-baret github-vincent-baret force-pushed the add_fullname_message_in_json_format_exception branch 4 times, most recently from 2b87551 to 1315cf6 Compare July 21, 2023 13:38
@github-vincent-baret github-vincent-baret changed the title Add field name and exception in JsonFormatException when parsing failed Add field name to error when failing to parse a field of type Message Jul 24, 2023
@github-vincent-baret github-vincent-baret force-pushed the add_fullname_message_in_json_format_exception branch from 1315cf6 to 3c49e78 Compare July 24, 2023 09:19
@github-vincent-baret github-vincent-baret marked this pull request as ready for review July 24, 2023 09:30
@github-vincent-baret
Copy link
Author

Hi @thesamet Do you think this PR is ok for review?

} catch {
case ex: JsonFormatException =>
throw new JsonFormatException(
s"Failed parsing field ${fd.name}: ${ex.getMessage}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With nested messages, wouldn't this lead to something that looks like:
"Failed parsing field x: failed parsing field y: failed parsing field z: reason"? Can this be changed somehow so the full path appears once?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @thesamet , sorry the person who opened that PR left my company so didn't follow up.
Indeed for this input """{"optMessage": { "optMessage": 39} }""" the error message would be

Failed parsing field opt_message: Failed parsing field opt_message: Expected an object for jsontest.MyTest, found JInt(39)

I don't know well this code base and I'm not seeing any trivial way to change it to a full path instead. I guess that might require subtyping JsonFormatException to accumulate a path for failure in nested objects, and I have no idea if adding that kind of complexity would be worth it or acceptable for the project.

Current implementation may not be the cleanest message, but it's simple and at least it's giving a helpful message, while without this implementation the message would be instead

Expected an object for jsontest.MyTest, found JInt(39)

Leaving the user clueless about where this is happening, especially for another type of error like "expected string and got number".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants