Skip to content

How to use question marks in tonic-build async method ? anyhow way or Result<Xxx, Box<dyn Error>> #716

Answered by davidpdrsn
xiuno asked this question in Q&A
Discussion options

You must be logged in to vote

If the error type is local to your crate you can define impl From<MyError> for Status and then ? will work directly.

Doesn't work for anyhow though. That requires using map_err. An anyhow::Error can happen for whatever reason, so tonic couldn't fine a general mapping. Therefore you're required to pick which status is appropriate with map_err.

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@xiuno
Comment options

@davidpdrsn
Comment options

@xiuno
Comment options

@davidpdrsn
Comment options

@gcxfd
Comment options

Answer selected by xiuno
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #715 on July 11, 2021 15:57.