I was using thiserror with the AWS Lambda Runtime, which requires Send
trait. I just decided I wanted to add more context to my errors. So, naturally I used map_err
and/or match
on the Err
and move it in the appropriate type.
But, somehow anything besides the ?
Try operator results in a ControlFlow
and so I'm stuck:
= help: the trait `Send` is not implemented for `(dyn std::error::Error + 'static)`
note: future is not `Send` as this value is used across an await
--> src/main.rs:550:26
|
47 | .output(match serde_json::to_string(&obj) {
| _________________________________-
48 | | Ok(json) => Ok(json),
49 | | Err(err) => Err(MyError::Json {
50 | | err,
51 | | text: "More context".to_owned(),
52 | | }),
53 | | }?)
| |__________________________- has type `ControlFlow<Result<Infallible, MyError>, std::string::String>` which is not `Send`
54 | .send()
55 | .await?;
| ^^^^^ await occurs here, with the value maybe used later
So, is there no way to avoid ControlFlow
and yet still accomplish changing the MyError
to a different Enum variant the way I am intending?