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

RSDK-5399 - surface component errors in gRPC handler #96

Merged

Conversation

gvaradarajan
Copy link
Member

No description provided.

Copy link
Member

@npmenard npmenard left a 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()

@gvaradarajan gvaradarajan force-pushed the RSDK-5399-better-errors-from-grpc branch from 8761566 to b60508d Compare October 23, 2023 21:17
@gvaradarajan gvaradarajan requested a review from npmenard October 23, 2023 21:18
@gvaradarajan gvaradarajan force-pushed the RSDK-5399-better-errors-from-grpc branch from b60508d to ee3095a Compare October 24, 2023 14:55
@@ -1067,6 +1069,57 @@ impl GrpcError {
}
}

#[derive(Debug)]
pub struct ServerError {
Copy link
Member

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 issourcesource: Option<anyhow::Error>, }

Or is it causing issue with non standard fields?

Copy link
Member Author

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

Copy link
Member Author

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

@gvaradarajan gvaradarajan force-pushed the RSDK-5399-better-errors-from-grpc branch from 5d8385d to c431c1f Compare October 27, 2023 16:32
@gvaradarajan gvaradarajan requested a review from npmenard October 27, 2023 16:34
Copy link
Member

@npmenard npmenard left a 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),
Copy link
Member

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

Copy link
Member Author

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

@gvaradarajan gvaradarajan merged commit 3893472 into viamrobotics:main Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants