http-rs / http-rs/surf

The error type does not always work with ?

Open
#158 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
1.5k
Forks
128
PR merge metrics
No merged PRs in 30d

Description

Example:

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

Error:

```rust
|
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
= note: required because of the requirements on the impl of `std::error::Error` for `std::boxed::Box`
= note: required because of the requirements on the impl of `std::convert::From>` for `anyhow::Error`
= note: required by `std::convert::From::from`
```

Workaround:

```rust
async fn fetch(url: String, sender: Sender) -> 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`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.