-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Change MarshalResponse and UnmarshalRequest to gracefully handle a proto type check error #470
Change MarshalResponse and UnmarshalRequest to gracefully handle a proto type check error #470
Conversation
We should probably just fix this in MarshalResponse: add a |
Sounds good! Will do. |
0c5deb2
to
d3cf42b
Compare
Updated the PR. @bdarnell , could you take another look? I can also change the code to fall back to JSON instead of returning an error. |
err = Errorf("unable to marshal %+v to protobuf: %s", value, err) | ||
msg, ok := value.(gogoproto.Message) | ||
if !ok { | ||
err = Errorf("unable to convert %+v to protobuf", value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't return an error if someone sends Accept: protobuf
when we can't support it (we don't reject requests that have completely unknown values in the accept header). Move the gogoproto.Message conversion earlier and if it fails set protoIdx to MaxInt32 (just as if protobuf weren't in the accept header at all).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, updated the PR. Does this look better now?
d3cf42b
to
9898a0e
Compare
LGTM |
Change MarshalResponse and UnmarshalRequest to gracefully handle a proto type check error
I'm still learning Go, and the main motivation of this PR is to add a test. I'm not totally sure the change to permission.go makes sense. Falling back to JSON would be better than panic, but partially supporting protobuf encoding (i.e., protobuf encoding is fine when a key is given) doesn't look very clear.