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

In connect unary protocol, fallback to code based on HTTP status if unable to deserialize it #702

Merged
merged 2 commits into from
Mar 6, 2024

Conversation

jhump
Copy link
Member

@jhump jhump commented Feb 28, 2024

The conformance tests, as of v1.0.0-rc3, currently require behavior that matches the current behavior of connect-go: if the error JSON body in a Connect unary response can be unmarshaled but is missing the code, it defaults to using "unknown" as the code.

However, in the Connect unary format (and not any of the others), we also have a non-200 HTTP status that could be used to determine a potentially better default than "unknown". So this PR changes it so that connect-go uses the HTTP status in this case, instead of always using "unknown". (Also see connectrpc/conformance#810.)

It also updates the JSON unmarshaling of the error body so it accepts a "code" property with an invalid value. In this case, the invalid value is discarded, and due to the change described above, the code will instead be computed from the HTTP status. But this lenience allows us to capture the message and details, in the event that the JSON contains these other properties but with (for example) a misspelled code string.

@jhump
Copy link
Member Author

jhump commented Feb 28, 2024

cc @srikrsna-buf

Copy link
Member

@akshayjshah akshayjshah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small asks, but the approach lgtm.

if wireErr.Code == 0 {
// code not set? default to one implied by HTTP status
wireErr.Code = connectHTTPToCode(response.StatusCode)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also open a PR to add this nuance to the wire protocol docs? This feels less like a behavioral specification and more like an aspect of the wire protocol itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roger that.

Copy link
Member Author

@jhump jhump Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was in the process of adding this and then noticed this existing paragraph in the section of the spec that describes the status code of the Unary-Response production:

When reading data from the wire, client implementations must use the HTTP-to-Connect mapping to infer a Connect error code if Bare-Message is missing or malformed.

IMO, this falls into this category. So it's arguable that always defaulting to "unknown" (as was previously done) was actually a bug.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do you think the existing language needs an update or clarification?

protocol_connect.go Outdated Show resolved Hide resolved
@akshayjshah
Copy link
Member

akshayjshah commented Mar 6, 2024 via email

@jhump jhump merged commit 75d634f into main Mar 6, 2024
12 checks passed
@jhump jhump deleted the jh/handle-invalid-code branch March 6, 2024 15:38
@jhump jhump added the bug Something isn't working label Mar 20, 2024
@jhump jhump mentioned this pull request Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants