-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Better error signaling in protojson.Unmarshal()
function
#1412
Comments
I recommend against Ideally, the |
OK, fair enough. Could you confirm, that every error returned from Also, there is no need to fix error types to provide meaningful information. Package can provide helper functions that take generic But maybe it's not worth changing the current implementation, since a new one is already planned? On the other hand, it will take at least half a year, before the enhanced json package hits production Go release (not sure, but I don't see that works on your proposal has already started) . |
One more thing. Should I close the issue? |
Probably true. There's a new
That's a question for the current maintainers of Go protobuf. I no longer work on this project. |
I'm closing this issue as there's no action needed on our end till a v2 json package is released and evaluated if it'll be a fit here which can be a separate issue. |
Thanks for your support. One more thing. I notice that output from Marshal function is documented as unstable (I even notice that this is enforce in the code). The question is how it is supposed to change in the future. I hope this only applies to the JSON formatting (white spaces, indentations, etc) and not for example to how fields names and enums values are encoded. I don't want to end up with unstable REST API for my grpc services. |
The unstable output is there so that we can change the JSON output to something that is semantically equivalent but might have superficial changes to the output and avoid breaking anyone who happens to be depending on the output being byte-for-byte identical for all time. Now, stable output is still a useful property, but it should be a feature that we opt into, rather than on by default. See #1121. |
As noted, the changes are only in semantically equivalent situations. The areas where you express the most concern (field names and enum encoding) are specified by the JSON-mapping for proto3, and thus have been stabilized. |
The field names will not changes, but it's possible that the order could change. Ordering of JSON objects have no semantic meaning according to RFC 8259 (per section 4). |
Is your feature request related to a problem? Please describe.
Errors returned by
protojson.Unmarshal()
are undocumented and hard (if not impossible) to parse or handle.Context: I need to wrap GRPC services/methods with REST endpoints. Part of this is translating JSON structs to protobuf messages.
protojson.Unmarshal()
function seems an obvious choice to have this done. Unfortunately errors returned from this function can not be easily translated to something meaningful for the client.Example errors returned from
Unmarshal()
function:All above errors are returned as values of type
*errors.prefixError
. And because this is a private type I can not useerrors.As()
to handle different types of errors in different ways (although, I don't even know ifprotojson.Unmarshal()
returns other error types; there is nothing about errors in the package documentation).Describe the solution you'd like
The text was updated successfully, but these errors were encountered: