tag1consulting / goose

Load testing framework, inspired by Locust
https://tag1.com/goose
Apache License 2.0
759 stars 69 forks source link

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

Closed huangjj27 closed 1 year ago

huangjj27 commented 1 year ago

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)))?;
jeremyandrews commented 1 year ago

Closing as duplicate of #531

huangjj27 commented 1 year ago

oh,I must have reposted this incidently. sorry~

jeremyandrews commented 1 year ago

Not a problem, thanks for the bug report!