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

Change MarshalResponse and UnmarshalRequest to gracefully handle a proto type check error #470

Merged
merged 2 commits into from
Mar 26, 2015

Conversation

kkaneda
Copy link
Contributor

@kkaneda kkaneda commented Mar 25, 2015

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.

@bdarnell
Copy link
Contributor

We should probably just fix this in MarshalResponse: add a , ok to the cast to proto.Message and if it doesn't pass, act as if proto encoding were not specified. We shouldn't have to pass an explicit list of encodings every time based on whether or not the argument is a proto.Message.

@kkaneda
Copy link
Contributor Author

kkaneda commented Mar 25, 2015

Sounds good! Will do.

@kkaneda kkaneda force-pushed the kkaneda/permission_empty_key branch 2 times, most recently from 0c5deb2 to d3cf42b Compare March 26, 2015 02:49
@kkaneda kkaneda changed the title Avoid panic when permission is requested with an empty key and "application/x-protobuf" content type Change MarshalResponse and UnmarshalRequest to gracefully handle a proto type check error Mar 26, 2015
@kkaneda
Copy link
Contributor Author

kkaneda commented Mar 26, 2015

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)
Copy link
Contributor

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).

Copy link
Contributor Author

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?

@kkaneda kkaneda force-pushed the kkaneda/permission_empty_key branch from d3cf42b to 9898a0e Compare March 26, 2015 16:05
@bdarnell
Copy link
Contributor

LGTM

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