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

the trait From<reqwest::error::Error> is not implemented for Box<TransactionError> #531

Closed
huangjj27 opened this issue Dec 25, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@huangjj27
Copy link

minimal repeatable code snippet:

async fn post_data(user: &mut GooseUser) -> TransactionResult {
    #[derive(Serialize)]
    #[serde(rename_all = "camelCase")]
    struct Json {
        data: Data,
    }

  let json = Json {
        data: Data {
           // omitted
        },
    };
    let mut goose = user
        .post_json("my/url", &json)
        .await?;
    let res = goose.response?;
}

then:

> cargo +nightly check                                     
    Checking myapp v0.1.0 (/path/to/my/app)
error[E0277]: `?` couldn't convert the error to `Box<TransactionError>`
  --> /path/to/my/app/src/main.rs:42:42
   |
42 |     let res = goose.response?;
   |                             ^ the trait `From<reqwest::error::Error>` is not implemented for `Box<TransactionError>`
   |
   = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
   = help: the following other types implement trait `From<T>`:
             <Box<(dyn StdError + 'a)> as From<E>>
             <Box<(dyn StdError + 'static)> as From<&str>>
             <Box<(dyn StdError + 'static)> as From<Cow<'a, str>>>
             <Box<(dyn StdError + 'static)> as From<std::string::String>>
             <Box<(dyn StdError + Send + Sync + 'a)> as From<&str>>
             <Box<(dyn StdError + Send + Sync + 'a)> as From<Cow<'b, str>>>
             <Box<(dyn StdError + Send + Sync + 'a)> as From<E>>
             <Box<(dyn StdError + Send + Sync + 'static)> as From<std::string::String>>
           and 18 others
   = note: required for `Result<(), Box<TransactionError>>` to implement `FromResidual<Result<Infallible, reqwest::error::Error>>`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `myapp` due to previous error

a quick fix is to wrap the error into a Box:

   // line 42
    let res = goose.response?;
        .map_err(|e| Box::new(TransactionError::Reqwest(e)))?;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants