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

Unexpected response on /v2/example/errorwithdetails #1842

Closed
isbang opened this issue Nov 27, 2020 · 2 comments · Fixed by #1843
Closed

Unexpected response on /v2/example/errorwithdetails #1842

isbang opened this issue Nov 27, 2020 · 2 comments · Fixed by #1843

Comments

@isbang
Copy link
Contributor

isbang commented Nov 27, 2020

🐛 Bug Report

When I run the example /v2/example/errorwithdetails, I got an unexpected message below.

{
  "code": 13,
  "message": "failed to marshal error message"
}

To Reproduce

  1. Setup Docker
docker run -it -p 8080:8080 golang:1.15 /bin/bash
  1. Setup environment inside of docker
apt-get update && apt-get install npm -y && npm install -g gulp-cli
GO111MODULE=on go get github.com/grpc-ecosystem/grpc-gateway/v2
cd /go/pkg/mod/github.com/grpc-ecosystem/grpc-gateway/[email protected]/examples/internal/browser
npm install && gulp bower && gulp backends
  1. Test example outside of the docker
curl -X GET --header 'Accept: application/json' 'http://localhost:8080/v2/example/errorwithdetails'

Expected behavior

Response message below

{
  "code": 2,
  "message": "with details",
  "details": [
    {
      "stackEntries": [
        "foo:1"
      ],
      "detail": "error debug details"
    }
  ]
}

func (s *_ABitOfEverythingServer) ErrorWithDetails(ctx context.Context, msg *emptypb.Empty) (*emptypb.Empty, error) {
stat, err := status.New(codes.Unknown, "with details").
WithDetails(&errdetails.DebugInfo{
StackEntries: []string{"foo:1"},
Detail: "error debug details",
})
if err != nil {
return nil, status.Errorf(codes.Internal, "unexpected error adding details: %s", err)
}
return nil, stat.Err()
}

Actual Behavior

Response message bellow with status code 500

{
  "code": 13,
  "message": "failed to marshal error message"
}

Your Environment

Mac os Catalina v10.15.7
Docker version 19.03.13, build 4484c46d9d
Image golang:1.15

@johanbrandhorst
Copy link
Collaborator

TIL we have a gulpfile in the depths of the examples 😆. Thanks for digging this up. I expect this is happening because the grpc-gateway server defined in https://github.com/grpc-ecosystem/grpc-gateway/tree/master/examples/internal/gateway doesn't have a way to understand the error details defined in the message returned from the gRPC server. It needs to import google.golang.org/genproto/googleapis/rpc/errdetails in order to be able to translate these messages from protobuf to JSON.

Would you like to contribute this fix and confirm it works?

@isbang
Copy link
Contributor Author

isbang commented Nov 27, 2020

I am not sure if I can fix this but I hope to try. May I try this?

In my opinion, main.opts from grpc-gateway/examples/internal/cmd/example-gateway-server/main.go#L26 needs Mux contains ErrorHandlerFunc to translate errdetails message. How do you think?

It needs to import google.golang.org/genproto/googleapis/rpc/errdetails in order to be able to translate these messages from protobuf to JSON.

I understood too late about this. Let me do this. 😄

isbang added a commit to isbang/grpc-gateway that referenced this issue Nov 27, 2020
add missing errdetails import so that protojson can
translate errdetails as google.protobuf.Any

fix grpc-ecosystem#1842
johanbrandhorst pushed a commit that referenced this issue Nov 28, 2020
* Fix broken example

add missing errdetails import so that protojson can
translate errdetails as google.protobuf.Any

fix #1842

* Regenerated bazel files
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 a pull request may close this issue.

2 participants