Skip to content

No support custom grpc error status code in @grpc/grpc-js package different with grpc(c core) #2151

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

Closed
BobDu opened this issue Jun 29, 2022 · 5 comments

Comments

@BobDu
Copy link

BobDu commented Jun 29, 2022

Problem description

No support custom grpc error status code in @grpc/grpc-js package different with grpc(c core)
When My Golang server respone a custom grpc error status code, @grpc/grpc-js only get code 2 Unknow.

Reproduction steps

https://github.com/BobDu/grpc-errors-demo
see this code repository. The focus is on the commits after my fork.

I define a Custom Error Status enum in proto.
hello.proto

// my custom grpc error code
enum ErrorCode {
    OK = 0;
    CUSTOM_ERROR = 88;
}

In golang service. throw a grpc err with custom status.
go/server.go

func (s *HelloServer) SayHelloCustomErr(ctx context.Context, req *api.HelloReq) (*api.HelloResp, error) {
	return nil, status.Errorf(codes.Code(api.ErrorCode_CUSTOM_ERROR.Number()), api.ErrorCode_CUSTOM_ERROR.String())
}

when i call this service use grpcurl. get it.

$ grpcurl -vv -plaintext -d '{"Name": "sssssssssssssssssss"}' --proto hello.proto 127.0.0.1:50051 hello.HelloService/SayHelloCustomErr

Resolved method descriptor:
rpc SayHelloCustomErr ( .hello.HelloReq ) returns ( .hello.HelloResp );

Request metadata to send:
(empty)

Response headers received:
(empty)

Response trailers received:
content-type: application/grpc
Sent 1 request and received 0 responses
ERROR:
  Code: Code(88)
  Message: CUSTOM_ERROR

when i use grpc (c core) client. The error code is 88 as expected.

$ node node/client.js
(node:18075) DeprecationWarning: grpc.load: Use the @grpc/proto-loader module with grpc.loadPackageDefinition instead
88 undefined: CUSTOM_ERROR
88

But, when i use @grpc/grpc-js client ,the result is 2 Unkonw.

$ node node2/client.js
2 UNKNOWN: CUSTOM_ERROR
2

Environment

in my demo code repository config file.

Additional context

N/A

@murgatroid99

thanks.

@BobDu
Copy link
Author

BobDu commented Aug 3, 2022

@murgatroid99 Can I provide anything further to resolve this issue as soon as possible?

@murgatroid99
Copy link
Member

There's nothing else you need to provide. I have just been focused on other things. This change also requires changes in multiple places that assume that the code is in the status enum.

@Vorobeyko
Copy link

@murgatroid99 Hi! When you can fix this issue?

@BobDu
Copy link
Author

BobDu commented Feb 11, 2025

@murgatroid99

Sorry to bother you again. I just want to know if this problem can be fixed.
It has prevented us from grpc(c core) upgrading to @grpc/grpc-js for many years.
Furthermore, it prevents us from upgrading nodejs version.

I understand that the open-source community is not obligated to resolve these issues, and I hope it won't put too much pressure on you. I just wanted to let you know that we are still looking forward to a fix for this problem.

@murgatroid99
Copy link
Member

It looks like the current behavior of the library is actually what you want, so you can switch now. It looks like the change happened in the 1.10.7 release unintentionally as a part of #2723.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants