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 error type does not always work with ? #158

Open
ghost opened this issue Apr 1, 2020 · 1 comment
Open

The error type does not always work with ? #158

ghost opened this issue Apr 1, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Apr 1, 2020

Example:

async fn fetch(url: String, sender: Sender<String>) -> anyhow::Result<()> {
    let body = surf::get(&url).recv_string().await?;
    sender.send(body).await;
    Ok(())
}

Error:

  |
9 |     let body = surf::get(&url).recv_string().await?;
  |                                                   ^ doesn't have a size known at compile-time
  |
  = help: the trait `std::marker::Sized` is not implemented for `dyn std::error::Error + std::marker::Send + std::marker::Sync`
  = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
  = note: required because of the requirements on the impl of `std::error::Error` for `std::boxed::Box<dyn std::error::Error + std::marker::Send + std::marker::Sync>`
  = note: required because of the requirements on the impl of `std::convert::From<std::boxed::Box<dyn std::error::Error + std::marker::Send + std::marker::Sync>>` for `anyhow::Error`
  = note: required by `std::convert::From::from`

Workaround:

async fn fetch(url: String, sender: Sender<String>) -> anyhow::Result<()> {
    let body = surf::get(&url)
        .recv_string()
        .await
        .map_err(|e| anyhow!(e))?;
    sender.send(body).await;
    Ok(())
}

I think the proper solution is for the error type (Exception) to be a dedicated type that implements std::error::Error.

@abreis
Copy link

abreis commented Apr 2, 2020

See #86 for some previous discussion on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant