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

grpcerrors: adapt grpcerrors to support more enriched error structures #5203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jsternberg
Copy link
Collaborator

The grpcerrors package has been updated to support more enriched error structures.

The serialization structure has been changed to capture the original structure of the error and to serialize and deserialize into that same structure. Wrapped errors should be maintained with the same structure for unwrapping.

Unwrap() []error is now supported so errors.Join and anything else that wraps multiple errors can now be used and are serialized/deserialized correctly.

More methods of determining the grpc code are now supported and they will respect error wrapping. The errors in
github.com/containerd/errdefs are now also used for mapping error codes with more likely to appear in the future.

The marshaling will marshal both the new format and the old format in a way where a client that reads either will succeed. That makes this method compatible with old clients.

@jsternberg
Copy link
Collaborator Author

I still need to finish the v1 compatibility tests. I also discovered a bug in typeurl while I was working on this and that's filed here: containerd/typeurl#47.

// stack.Stack is affected by the same bug as the other
// typed errors so reuse that marshaling function to
// marshal the stack trace.
return marshalTypedError(st)
}

func Code(err error) codes.Code {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code here looks good and favors the right error code but it might be good to define that in the docs.

@jsternberg
Copy link
Collaborator Author

I tried to do this with just using the Status protobuf message but the implementation is so much easier and more future proof if I just add a single type rather than overload the status protobuf message. So, I've updated this with that implementation accordingly.

@jsternberg jsternberg force-pushed the grpc-errdefs branch 3 times, most recently from 2731511 to 7fe8b20 Compare August 5, 2024 19:04
The grpcerrors package has been updated to support more enriched error
structures.

The serialization structure has been changed to capture the original
structure of the error and to serialize and deserialize into that same
structure. Wrapped errors should be maintained with the same structure
for unwrapping.

`Unwrap() []error` is now supported so `errors.Join` and anything else
that wraps multiple errors can now be used and are
serialized/deserialized correctly.

More methods of determining the grpc code are now supported and they
will respect error wrapping. The errors in
`github.com/containerd/errdefs` are now also used for mapping error
codes with more likely to appear in the future.

The marshaling will marshal both the new format and the old format in a
way where a client that reads either will succeed. That makes this
method compatible with old clients.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants