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

Better grpc error strings #87

Closed
floridoo opened this issue Jan 8, 2016 · 11 comments
Closed

Better grpc error strings #87

floridoo opened this issue Jan 8, 2016 · 11 comments

Comments

@floridoo
Copy link

floridoo commented Jan 8, 2016

Errors currently look similar to this:

{
  "error": "rpc error: code = 16 desc = \"Unauthenticated\""
}

Wouldn't it be better to set error just to the description?

Example:

{
  "error": "Unauthenticated"
}

This can easily be achieved by replacing err.Error() with grpc.ErrorDesc(err) on this line:
https://github.com/gengo/grpc-gateway/blob/master/runtime/errors.go#L77

I can send a pull request if wished.

@pgracio
Copy link

pgracio commented Jan 9, 2016

+1

1 similar comment
@johansja
Copy link
Contributor

+1

@yugui
Copy link
Member

yugui commented Jan 12, 2016

I don't think it is better to lose error code in the message.
So I still slightly prefer err.Error(). Why do you think grpc.ErrorDesc(err) is better?

@johansja
Copy link
Contributor

Maybe it is OK to lose error code in the message and make it cleaner. GRPC error code is translated into HTTP status code anyway in the next few line - https://github.com/gengo/grpc-gateway/blob/master/runtime/errors.go#L88 .

@floridoo
Copy link
Author

How about this then:

{
  "error": "Unauthenticated",
  "code": 16
}

@yugui
Copy link
Member

yugui commented Jan 20, 2016

@floridoo It is not too bad. But I still don't understand what's wrong in the current format of the message.

@dmitshur
Copy link
Contributor

If I understand correctly, what people don't like is that the strings rpc error: code = and desc = are there in every single error message. They're not the actual content, so including them in the output is potentially pointless, it could be considered noise.

I don't feel very strongly about this either way.

@kazegusuri
Copy link
Contributor

I prefer structured log than combined log because we can take what we want from logs easily.
So +1 to separate to error and code.

@yugui
Copy link
Member

yugui commented Jan 26, 2016

OK. I will accept it if you give me a pull request with the style:

{
  "error": "Unauthenticated",
  "code": 16
}

floridoo pushed a commit to floridoo/grpc-gateway that referenced this issue Jan 26, 2016
@yugui yugui closed this as completed in 7a385fe Jan 27, 2016
achew22 pushed a commit to achew22/grpc-gateway that referenced this issue Feb 9, 2016
@dadgar
Copy link
Contributor

dadgar commented Apr 14, 2020

Bumping this issue. Is there any way to get the string representation of the code? If exposed to public users, the code doesn't really provide much value. They would have to know to look it up in the codes proto file. Google Cloud for example returns both which is nice. https://cloud.google.com/apis/design/errors#http_mapping

@johanbrandhorst
Copy link
Collaborator

It's possible to customize error returns already. Changing the error return structure at this point would break many users. For 2.0 (if that ever comes around) we want to have a serious look at the error returns again. See https://grpc-ecosystem.github.io/grpc-gateway/docs/customizingyourgateway.html.

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

8 participants