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

Example of a possible fix for indicating server errors #374

Merged
merged 12 commits into from
Oct 17, 2022

Conversation

joshcarp
Copy link
Contributor

@joshcarp joshcarp commented Oct 13, 2022

Add connect.IsWireErr, so clients can distinguish synthesized from server-sent errors.

Fixes #222.

@joshcarp joshcarp marked this pull request as ready for review October 14, 2022 15:26
@joshcarp joshcarp requested a review from akshayjshah October 14, 2022 15:26
@joshcarp joshcarp linked an issue Oct 17, 2022 that may be closed by this pull request
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.

The overall approach looks good! Before we merge these changes in, let's get the code that sets isServerErr closer to the HTTP layer.

// IsServerErr returns true if the error was produced by the server.
func (e *Error) IsServerErr() bool {
return e.isServerErr
}
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer not to export this method - we've already got connect.IsServerErr.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that case the method isn't really needed because it's the same as inspecting the field

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed IsServerErr, can be reintroduced if we ever need it

Copy link
Member

Choose a reason for hiding this comment

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

Yep, sounds right to me!

error.go Outdated
}

// NewError annotates any Go error with a status code.
func NewError(c Code, underlying error) *Error {
return &Error{code: c, err: underlying}
}

// IsServerErr returns true if the error was produced by the server.
Copy link
Member

Choose a reason for hiding this comment

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

Let's rethink this name a little; IsServerErr suggests to me that we're categorizing errors into 4xx and 5xx. Perhaps IsFromWire?

Also, can we give some examples in the GoDoc? I think the idea is approachable, but a little subtle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do like IsFromWire

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although talking API design we probably want it to be IsWireErr because connect.IsFromWire doesn't give enough context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

field changed to wireErr bool and function changed to connect.IsWireErr(bool) for simplicity but also context around the fact that an error is still being checked

@@ -478,6 +479,7 @@ func (cc *connectStreamingClientConn) Receive(msg any) error {
// For users to realize that the stream has ended, Receive must return an
// error.
serverErr.meta = cc.responseHeader.Clone()
serverErr.isServerErr = true
Copy link
Member

Choose a reason for hiding this comment

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

I think we can avoid both this change and the one above by handling this closer to the wire - let's add this code to connectWireError.asError instead.

@akshayjshah akshayjshah merged commit 773ad30 into main Oct 17, 2022
@akshayjshah akshayjshah deleted the feat/server-err branch October 17, 2022 21:57
akshayjshah pushed a commit that referenced this pull request Jul 26, 2023
Add `connect.IsWireErr`, so clients can distinguish synthesized from
server-sent errors.

Fixes #222.
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.

Clients can't differentiate server-sent and client-synthesized errors
2 participants