Repository navigation
Keep Response.Error when encoding a protobuf body - #187
Open
HakeemTheEmperor wants to merge 1 commit into
Open
HakeemTheEmperor wants to merge 1 commit into
HakeemTheEmperor wants to merge 1 commit into
Conversation
EncodeAsProtobuf, EncodeAsLegacyProtobuf and EncodeAsProtobufJSON set r.Error = terrors.Wrap(err, nil) even when the write succeeded, which overwrote any error already on the response with nil. ErrorFilter hits this when the request has Accept: application/protobuf, so failed requests came back with a nil error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #186
EncodeAsProtobuf,EncodeAsLegacyProtobufandEncodeAsProtobufJSONended with:When the write succeeds,
terrors.Wrap(nil, nil)returns nil, so any error already on the response was overwritten.ErrorFiltersetsrsp.Errorand then encodes the terror into the body, and withAccept: application/protobufthat goes throughEncodeAsLegacyProtobuf. Failed requests from protobuf clients therefore came back withrsp.Error == nil, andDecodewould read the terror into the caller's message.This changes the three methods to only set
r.ErrorwhenWritefails, which is whatEncodeAsJSONalready does.Tests:
TestResponseProtobufEncodersKeepExistingErrorchecks that each of the three encoders keeps an existing errorTestErrorFilterKeepsErrorForAllAcceptTypeschecks thatErrorFilterkeeps the error for both JSON and protobufAcceptheadersBoth fail on master and pass with this change.
go vet ./...andgo test ./...pass.