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

GRPC transport errors #389

Closed
kushtrimjunuzi opened this issue Nov 8, 2016 · 3 comments
Closed

GRPC transport errors #389

kushtrimjunuzi opened this issue Nov 8, 2016 · 3 comments
Assignees

Comments

@kushtrimjunuzi
Copy link

kushtrimjunuzi commented Nov 8, 2016

There is a situation that I want to retrieve grpc error not fmt.Errorf and looking at the code https://github.com/go-kit/kit/blob/master/transport/grpc/client.go#L93 is returning fmt.Errorf, is there any idiomatic way to retrieve grpc error type when invoking the rpc?

Looking at https://github.com/grpc/grpc-go/blob/master/rpc_util.go#L363 grpc has a method to retrieve error message, we can return an error struct containing grpc error, the struct will be ex.

type rpcError struct{
  rpc error
  err error
}

func(e *rpcError) Error() string{
  return e.err.Error()
}

func (e *rpcError) RPC() error{
  return e.rpc
}

at gokit change will be:

return nil, &rpcError{rpc: err, err: fmt.Errorf("Invoke: %v", err)}
at consumer will be:

type rpcError interface {
  RPC()
}

rpcerr:=err.(rpcError).RPC()
errstr:=grpc.ErrorDesc(rpcerr)

Just an idea, what do you think?

@peterbourgon
Copy link
Member

From the Go kit mailing list, I'll copy my email:

We wrap errors in transport/http in a similar way to the proposed, but I'm not convinced it actually brings any value. Does anyone actually switch calling code behavior based on the returned err.Domain? If not, I would vote for removing context altogether, and returning the raw
error. Thoughts?

I didn't get any strong pushback on the thread; any thoughts here?

@basvanbeek
Copy link
Member

I have no objection returning the raw errors and haven't noticed any benefits to Domain errors while working with services in production.

@peterbourgon
Copy link
Member

Closed with #407!

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

No branches or pull requests

3 participants