stalwartlabs / mail-send

E-mail delivery library for Rust with DKIM support
https://docs.rs/mail-send/
Apache License 2.0
202 stars 21 forks source link

some error with error display (i don't know how to describe accurate) #5

Closed oh0123 closed 2 years ago

oh0123 commented 2 years ago

mail-send::Error can't enum by thiserror crate.

image

mdecimus commented 2 years ago

Not sure how to interpret that message, both Debug and Display are implemented in mail-send's Error. Perhaps you could wrap mail-send's Error into your own error type that supports thiserror?

LeoniePhiline commented 1 year ago

The problem here was that the std::error::Error trait is not implemented for mail_send::Error. I've opened #11 about that.

Here's a better error message to showcase the issue (note the the following trait bounds were not satisfied: mail_send::Error: std::error::Error):

error[E0599]: the method `as_dyn_error` exists for reference `&mail_send::Error`, but its trait bounds were not satisfied
   --> mail/src/error.rs:15:13
    |
15  |     #[error("failed to send mail")]
    |             ^^^^^^^^^^^^^^^^^^^^^ method cannot be called on `&mail_send::Error` due to unsatisfied trait bounds
    |
   ::: /path/to/.cargo/registry/src/github.com-1ecc6299db9ec823/mail-send-0.3.1/src/lib.rs:139:1
    |
139 | pub enum Error {
    | --------------
    | |
    | doesn't satisfy `mail_send::Error: AsDynError<'_>`
    | doesn't satisfy `mail_send::Error: std::error::Error`
    |
    = note: the following trait bounds were not satisfied:
            `mail_send::Error: std::error::Error`
            which is required by `mail_send::Error: AsDynError<'_>`
            `&mail_send::Error: std::error::Error`
            which is required by `&mail_send::Error: AsDynError<'_>`

There is a workaround (using .map_err() rather than #[from] with #[error("description")]), but it could be real neat if the standardized std::error::Error trait was supported, as the mainstream error handling libraries build upon it and it makes life easier. :)