-
Notifications
You must be signed in to change notification settings - Fork 1.6k
jsonpb: Unmarshal returns generic error on unknown fields #551
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
Comments
I understand that the type mentioned is specific to Go, but I don't understand why new API has to be exported to support this. Why can't we just change the error message to use the canonical message name of the proto type? |
For a JSON-based API, there is arguably no "canonical message name". Unless Protobuf magically starts supporting a mapping to JSON Schema, OpenAPI or similar. We have a specific use case where gRPC is available internally, but the JSON marshaler is used for a consumer-facing API. These error messages, referring to internal types inside the app, are confusing. (Adding to the confusion is that the consumer of this API cannot get a position inside the JSON.) |
This project is fundamentally about protocol buffers. The canonical proto message name should be sufficient to describe which message is problematic. I believe it is reasonable for a user to be aware of the proto definitions since the JSON schema is derived from the JSON<->Protobuf specification. Exposing API for a more structured error is a dangerous slippery slope to go down. There are many possible failure modes for protos, and this should not be a precedent that we add API for every possible failure scenario. |
This project is also about a mapping between Protobuf and JSON. Plenty of people use the grpc-gateway, which relies on the JSON marshaling. A JSON client shouldn't need to know that there's a gRPC system underneath. When designing layered systems, you want to be able to prevent underlying layers from leaking through. For example, consider, hypothetically, if I don't see where the "slippery slope" is. Go has error values for a reason. They should be used to provide enough information for a caller to intercept a specific use case. If that wasn't the case, then all Go errors would be strings. |
The documentation for grpc-gateway says that it uses Secondly, the documentation says it uses
That's not a strong argument since protos don't do anything of the sort. The error returned is distinctly related to protos, so its okay that it returns proto-specific information. The reasonable changes to possibly make are either:
The slippery slope is after adding
That's not a strong argument either. Go also has complex numbers; doesn't mean we should use them in protos. Also, we do use errors, we have just intentionally chosen not to provide structured errors to avoid bloating the API. The only form of structured errors we may consider are those that have semantic meaning in the realm of protos. |
Closing as duplicate of #266. I agree that the errors messages can be improve, but I don't see a compelling reason to provide structured errors. |
When
AllowUnknownFields
is false,Unmarshal
will produce an error string such as:This leaks the type
proto.Mutation
to clients, which should not need to see such internals when they are consuming a pure-JSON HTTP API. The only way for an app to prevent this is to use a regexp to detect this specific unmarshaling error, which is not acceptable.There are other instances of
fmt.Errorf
being used, but this is the main one that leaks.Fixed in this PR, which was rejected for not creating an issue first.
The text was updated successfully, but these errors were encountered: