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

Doesn't work with thiserror #335

Open
kvzn opened this issue Dec 28, 2021 · 6 comments
Open

Doesn't work with thiserror #335

kvzn opened this issue Dec 28, 2021 · 6 comments

Comments

@kvzn
Copy link

kvzn commented Dec 28, 2021

It's the same situation with this issue: dtolnay/thiserror#118

When I use Surf with thiserror like that:

#[error("SurfError")]
SurfError(#[from] surf::Error),

I got issue:

error[E0599]: the method `as_dyn_error` exists for reference `&surf::Error`, but its trait bounds were not satisfied
  --> src/errors.rs:80:13
   |
80 |     #[error("SurfError")]
   |             ^^^^^^^^^^^ method cannot be called on `&surf::Error` due to unsatisfied trait bounds
   |
  ::: /Users/jack/.cargo/registry/src/github.com-1ecc6299db9ec823/http-types-2.12.0/src/error.rs:16:1
   |
16 | pub struct Error {
   | ----------------
   | |
   | doesn't satisfy `surf::Error: AsDynError`
   | doesn't satisfy `surf::Error: StdError`
   |
   = note: the following trait bounds were not satisfied:
           `surf::Error: StdError`
           which is required by `surf::Error: AsDynError`
           `&surf::Error: StdError`
           which is required by `&surf::Error: AsDynError`

Can you solve this? Many thanks!

@mre
Copy link

mre commented Jan 30, 2022

Just in case anyone is looking for a workaround for the time being, you can do

#[derive(Debug, Error)]
pub enum Error {
    /// Network error (surf)
    #[error("Failed to make a request: {0:?}")]
    Http(surf::Error),
}

impl From<surf::Error> for Error {
    fn from(err: surf::Error) -> Self {
        Error::Http(err)
    }
}

@Fishrock123
Copy link
Member

I'm working on this but is requires a lot of changed to http-types first so it'l be a while at least

@spikespaz

This comment was marked as off-topic.

@Fishrock123

This comment was marked as off-topic.

@spikespaz
Copy link

@spikespaz Shame on you for trying to shame people who had no involvement in the original creation and who spent a bunch of time trying to fix it.

Did you try to fix it? Do you even realize that this project predated thiserror's wide acceptance?

Anyways I am marking these as off topic. You can contribute or not.

Then shame on the original authors. And your statement about predating thiserror doesn't matter, it didn't predate std::error::Error and that is my point.

@fundon
Copy link

fundon commented Jul 15, 2022

Add thiserror to Cargo.toml, It can fix that for me.

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

5 participants