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

feat: Return application level errors as a part of the gRPC response #462

Closed
erezrokah opened this issue Dec 5, 2022 · 6 comments
Closed

Comments

@erezrokah
Copy link
Member

erezrokah commented Dec 5, 2022

TLDR: We should consider having application level errors as a part of the gRPC responses, to make it easier to identify them.

For example in the following line:

return fmt.Errorf("failed to CloseAndRecv client: %w", err)

failed to CloseAndRecv is not necessarily correct, as err is whatever is returned from the following function:
func (s *DestinationServer) Write2(msg pb.Destination_Write2Server) error {
.

Not sure what's the best solution (need to do some research), but we could add an error(s) field to gRPC responses so we have a clear separation between application level errors and gRPC/communication level ones.

Also due to grpc/grpc-go#2934 we can't unwrap errors.

@erezrokah
Copy link
Member Author

Looks like we could use WithDetails for this https://pkg.go.dev/google.golang.org/grpc/internal/status#Status.WithDetails

kodiakhq bot pushed a commit that referenced this issue Dec 11, 2022


Related to #462 and also #477.
Two reasons for this change:
1. We shouldn't be using `codes.Internal` as it's generated internally by gRPC so we won't be able to distinguish between gRPC protocol errors and application level errors, see https://github.com/grpc/grpc-go/blob/eeb9afa1f6b6388152955eeca8926e36ca94c768/codes/codes.go#L166.
2. We don't really do anything with the code at the moment, it's only printed in a confusing way (see #477)

---
@yevgenypats
Copy link
Member

I understand the need for application level errors but I don't think it should have anything with grpc errors. depending on which errors we want to send we need to add it to the protobuf. grpc errors are mostly used when something bad happened on the server.

@erezrokah
Copy link
Member Author

I understand the need for application level errors

Most errors returned from

func (s *DestinationServer) Write2(msg pb.Destination_Write2Server) error {
are application level.

The only ones that could be related to gRPC protocol are:

return fmt.Errorf("write: failed to receive msg: %w", err)

return fmt.Errorf("failed to receive msg: %w", err)
, but also not necessarily depending on what error caused the stream to close

@yevgenypats
Copy link
Member

There can be also grpc errror returned after this function is returned that we actually saw when buffer is too big so there is no good way to distinguish both over the grpc error field.

@erezrokah
Copy link
Member Author

no good way to distinguish both over the grpc error field

Agree there could be both application errors and gRPC errors. Right now we're mixing both so the purpose of this issue is to discuss a solution so we can distinguish between them.

One approach is in #487, to use the status package as it essentially wraps the errors that are sent, along with the errdetails package. More in https://cloud.google.com/apis/design/errors#error_details

@erezrokah
Copy link
Member Author

Closing as won't fix as we've improved error reporting

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

No branches or pull requests

2 participants