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

Implement From<NonZeroI32> for GrpcCode #505

Open
1 task done
CodingAnarchy opened this issue Aug 29, 2024 · 0 comments · May be fixed by #506
Open
1 task done

Implement From<NonZeroI32> for GrpcCode #505

CodingAnarchy opened this issue Aug 29, 2024 · 0 comments · May be fixed by #506

Comments

@CodingAnarchy
Copy link

CodingAnarchy commented Aug 29, 2024

  • I have looked for existing issues (including closed) about this

Feature Request

GrpcCode does not provide the required From<T> implementations to easily be used over a tonic server that returns a tonic::Status with a tonic::Code. These logically are the same concept, but cannot be converted between these enums (and the numerical representaions) except by implementing your own matching logic.

Motivation

We are implementing a GrpcErrorsAsFailures for a tracing layer on top of a tonic server, and this returns a GrpcFailureClass::Code(NonZeroI32). It would be nice to have a simple path to convert this to a GrpcCode so we can leverage this in our tracing to get human-readable code strings.

Proposal

Similarly, if not identical, to impl From<i32> for tonic::Code.

Alternatives

The alternative is that users have to implement from_i32 or similar as methods themselves, which is potentially more error-prone than using a standard and common implementation, especially if gRPC status codes are changed in the future (such as to add new enumerated values for additional statuses).

gshipilov added a commit to gshipilov/tower-http that referenced this issue Aug 30, 2024
@gshipilov gshipilov linked a pull request Aug 30, 2024 that will close this issue
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.

1 participant