-
Notifications
You must be signed in to change notification settings - Fork 1k
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(types): Add gRPC Richer Error Model support (RetryInfo) #1095
Conversation
Start using `mod.rs` filenames. This makes the style more consistent across crates.
Add the code related to richer error model support to a new `richer_error` module. This improves readability and hopefully will make it easier to add new features to `tonic-types` in the future.
Following implementation at flemosr/tonic-richer-error.
Oh somehow this totally fell off my radar let me review this on monday! sorry about the delay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall have a few comments once those are addressed we can merge. Sorry for the delay again!
tonic-types/src/richer_error/mod.rs
Outdated
details, | ||
}; | ||
|
||
Bytes::from(status.encode_to_vec()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why encode to vec instead of using BytesMut + BufMut and regular encode
? So that we avoid the vec round trip?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using BytesMut
indeed makes much more sense, thanks! It seems to me that using BufMut
is not necessary in this case but I may be missing something.
tonic-types/src/richer_error/mod.rs
Outdated
|
||
/// Used to implement associated functions and methods on `tonic::Status`, that | ||
/// allow the addition and extraction of standard error details. | ||
pub trait StatusExt { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want to seal this trait similar to https://docs.rs/tower-http/latest/src/tower_http/builder.rs.html#45 that way outside users can't implement it and we can add more required fn as we please without making a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I did not know this pattern, quite useful. Thanks!
use super::super::pb; | ||
use super::super::{FromAny, IntoAny}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I like combining these since they have a similar path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed that, thanks!
Adjustments following suggestions by @LucioFranco in hyperium#1095. Improve `gen_details_bytes`, seal `StatusExt`, adjust imports style.
No problem! Hopefully I addressed all comments but please let me know if you think we should make any further changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Motivation
The gRPC Richer Error Model is quite useful to send additional feedback to clients, and is supported by many gRPC libraries in other languages.
Solution
This PR continues the work initiated at #1068. It improves the organization of
tonic-types
modules, and adds support for theRetryInfo
standard error message type to that crate.