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

expose an API for constructing a wire error #420

Closed
jhump opened this issue Dec 16, 2022 · 2 comments · Fixed by #437
Closed

expose an API for constructing a wire error #420

jhump opened this issue Dec 16, 2022 · 2 comments · Fixed by #437
Labels
enhancement New feature or request

Comments

@jhump
Copy link
Member

jhump commented Dec 16, 2022

When using connect.NewError, it is not possible create an error such that err.IsWireError() will return true.

This capability is particularly useful for dealing with bidi streaming APIs that represent a conversation, where each response message correlates with a request message. It is common for these kinds of APIs to support partial success by having a response message indicate a failure just for that one request message. Often such APIs use google.rpc.Status in the response message to indicate a possible failure. Sometimes they do not.

For this sort of use, it is commonplace for the calling Go code to translate that status into an error. Since the error was received over the wire during an RPC call, it should technically be a wire error, so that any other handling/propagation logic higher up the stack can react to it correctly.

This could be addressed as easily as introducing a new NewWireError function with the same signature and semantics as NewError except that the returned error will return true when err.IsWireError() is called.

@jhump jhump added the enhancement New feature or request label Dec 16, 2022
@akshayjshah
Copy link
Member

Huh, I'd never noticed that portion of the reflection API. TIL!

Happy to take a PR for this. I'm 50/50 on whether we ought to special-case NewWireError or anticipate more things down the road and add NewErrorOpt(Code, error, ...ErrorOption) (function name is terrible, but you get the idea).

@akshayjshah
Copy link
Member

akshayjshah added a commit that referenced this issue Jan 13, 2023
Currently, only the Connect runtime can create errors that return true
when tested by `IsWireError`. However, streaming RPCs commonly indicate
partial failure by including an error code and message in their response
message. To propagate these partial failures properly, clients need a
way to construct wire errors. This commit adds `NewWireError` to satisfy
this use case.

Fixes #420.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants