-
Notifications
You must be signed in to change notification settings - Fork 12
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
RSDK-5399 - surface component errors in gRPC handler #96
RSDK-5399 - surface component errors in gRPC handler #96
Conversation
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 would like to avoid using error code not officially listed by gRPC (see https://grpc.github.io/grpc/core/md_doc_statuscodes.html)
We can extend the GrpcError type to allow passing a cause and do something like err.to_string()
8761566
to
b60508d
Compare
b60508d
to
ee3095a
Compare
@@ -1067,6 +1069,57 @@ impl GrpcError { | |||
} | |||
} | |||
|
|||
#[derive(Debug)] | |||
pub struct ServerError { |
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.
Could we use thiserror like
#[derive(Error, Debug)] pub struct MyError { grpc_error: GrpcError, #[source] // optional if field name is
sourcesource: Option<anyhow::Error>, }
Or is it causing issue with non standard fields?
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 don't quite get what you mean here? Are you saying this?
#[derive(Debug, Error)]
pub struct ServerError {
grpc_error: GrpcError,
#[source]
cause: Option<anyhow::Error>,
}
The reason I didn't do that was because if a cause wasn't provided I wanted the source to be the GrpcError
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.
Never mind, I don't even know why I wanted that I'll change it
5d8385d
to
c431c1f
Compare
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
impl fmt::Display for ServerError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match &self.cause { | ||
Some(err) => write!(f, "{}: {}", self.grpc_error, err), |
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 may be able to delegate to Error's Display implementation
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.
it was a lot more complicated to try to do this because the Debug and Display traits both have the fmt
function with the same signature
No description provided.