How to use question marks in tonic-build async method ? anyhow way or Result<Xxx, Box<dyn Error>> #716
-
|
anyhow way, I can use question mark: but in tonic, I have to map_err() any where... is there better way ? if I define MyError and change Status to MyError, will get error Status not match MyError in trait. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
|
If the error type is local to your crate you can define Doesn't work for anyhow though. That requires using |
Beta Was this translation helpful? Give feedback.
-
|
use this https://crates.io/crates/tonic_catch , everything will be easy As shown in the figure below, I found that the answer was folded, and I paste it again for convenience |
Beta Was this translation helpful? Give feedback.

If the error type is local to your crate you can define
impl From<MyError> for Statusand then?will work directly.Doesn't work for anyhow though. That requires using
map_err. Ananyhow::Errorcan happen for whatever reason, so tonic couldn't fine a general mapping. Therefore you're required to pick which status is appropriate withmap_err.