-
Notifications
You must be signed in to change notification settings - Fork 77
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
How to return errors to clients? #32
Comments
My colleague @intractable solved this by writing monoid instances for the rpc response types. gRPC and proto3 lean heavily on "zero initialized" value semantics for the scalar types and some composite types (like enums and repeated, I think, but not for message types whose "missing value" semantics are language-dependent). The missing value for message types, in Go, is rendered using a pointer type. Our Haskell code generator renders it with a Maybe type. Therefore if you want Maybe-like semantics for fields of a response that are of a scalar type, you need to wrap those scalar types with a message type (i.e: "newtype" it). If you do this, then it's pretty easy to define what the identity for your monoid instance is. Once you have that then you can simply use For example: ServerNormalResponse mempty mempty StatusAborted (StatusDetails "my error message") Barring that. Knowing that scalar types have zero initialized values and that fields with a message type can be missing, you could construct a response type that is "zero initialized" and use that in your error response. If you wished to return richer information in a response that is not |
Well, the question didn't really stem from "Some fields can't be initialized", rather "There's no sensible value to return". Indeed, I could model this within the RPC spec, but then all my calls would return some kind of Mentioning Anyway: there must be some way to return an error to a client without including a full response value, otherwise how does Thanks for the info! |
@NicolasT I misinterpreted your question then, sorry. You can return an error from the server with a status code and description using a type of AFAIK, you produce a value of type The client will receive that information in a type of If you wish to return a response without it being delivered as a |
Oh one more thought w.r.t selection of a monoid for grpc proto response messages: the monoid @intractable selected for the response types implements the |
Doesn't seem to work. For instance, if I do this on the server side:
I get this on the client side:
|
(What I would like to get is |
Oh, nevermind, found the solution:
|
GHC 8.2 became more restrictive when checking default signatures, demanding an explicit equality constraint here. See also: ekmett/lens#712 Referenced there: https://ghc.haskell.org/trac/ghc/ticket/13258 https://ghc.haskell.org/trac/ghc/ticket/13249
It's a bit unclear to me how one is supposed to return an error to a client for a 'normal' RPC request, except by throwing an exception in a handler (which is quite ugly, because then said error gets logged as well, which may not be useful at all).
A handler is supposed to return a
ServerResponse 'Normal respType
, which isServerNormalResponse :: respType -> MetadataMap -> StatusCode -> StatusDetails -> ServerResponse 'Normal respType
. When a handler fails, i.e. is unable to calculate a proper value ofrespType
, how is one supposed to return a response with e.g.StatusAborted
to the client?The text was updated successfully, but these errors were encountered: