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

Translate errors grom google.golang.org/error to connect-go/error #763

Closed
franchb opened this issue Jul 5, 2024 · 1 comment
Closed
Labels
enhancement New feature or request

Comments

@franchb
Copy link

franchb commented Jul 5, 2024

Feature Request: Error Translation from gRPC to connect-go

Is your feature request related to a problem? Please describe.

I'm frequently encountering situations where I need to translate google.golang.org/grpc errors to connect-go errors. Currently, there's no straightforward way to do this, which leads to additional development time and potential inconsistencies in error handling across projects that are migrating from gRPC to connect-go.

Describe the solution you'd like

I propose adding a utility function or package within connect-go that can convert gRPC errors to their connect-go equivalents. This could be implemented as:

  1. A new function in the existing connect package:
func FromGRPCError(err error) error
  1. Or a new subpackage, e.g., connect/grpccompat:
package grpccompat

func FromGRPCError(err error) error   

This function would take a gRPC error as input and return the corresponding connect-go error, maintaining the original error's status code, message, and any additional details.

Describe alternatives you've considered

  1. Creating a separate, third-party package for this conversion. However, this approach may lead to fragmentation and inconsistency across projects using connect-go.

  2. Manually mapping errors in each project that needs this functionality. This is currently the default approach but is time-consuming and error-prone.

  3. Extending the existing connect.CodeOf function to handle gRPC errors directly. While this could work, it might clutter the primary API and could be confusing for users who don't need gRPC compatibility.

The proposed solution of adding a dedicated conversion function or package within connect-go seems to be the most clean and maintainable approach.

Additional context

This feature would greatly benefit projects that are in the process of migrating from gRPC to connect-go, as well as those that need to interact with both gRPC and connect-go services. It would ensure consistent error handling and reduce the cognitive load on developers working with both ecosystems.

@franchb franchb added the enhancement New feature or request label Jul 5, 2024
@franchb franchb changed the title Translate errors grom google.golang.org/errpr to connect-go/error Translate errors grom google.golang.org/error to connect-go/error Jul 5, 2024
@jhump
Copy link
Member

jhump commented Jul 5, 2024

@franchb, this would require adding a dependency from connect-go to the grpc-go module. That would then pull in lots of gRPC-related packages into every program that uses connect-go.

While one big objective of Connect is to providing support for HTTP 1.1 for web and mobile RPC clients, another is to provide libraries that are lightweight & simple and that use standard (or widely used) libraries and idioms for the target language. So pulling the behemoth that is grpc-go into connect-go's dependency graph is a non-starter.

The recommended way to do this is, in your own codebase (where I assume you are migrating a gRPC codebase to Connect and still have handlers and helpers that produce the gRPC error type), use an interceptor that examines all errors and translates them to Connect errors whenever it sees a gRPC error. This translation should be very straight-forward to do with the existing APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants