Closed U007D closed 3 weeks ago
@U007D yes, we slightly differ in behavior from thiserror
, so just blindly try to replace will unlikely work.
In this concrete case, the OsString
type doesn't implement std::error::Error
trait, that's why you see this error. The difference here between derive_more::Error
and thiserror::Error
is that:
thiserror::Error
requires specifying the Error
's source explicitly with the #[source]
attribute on the field (naming the field source
also works).derive_more::Error
implies single-fielded tuples as the Error
's source automatically.So the correct translation to derive_more
in this case will be:
use derive_more::{Display, Error, From};
#[derive(Debug, Display, Error, From)]
enum Error {
/// An error occurred while converting an `OsString` to UTF-8.
#[display("Error converting the following `OsString` to UTF-8: '{_0:?}'.")]
Utf8Conversion(#[error(not(source))] OsString),
// ...
}
See also "Ignoring fields for derives" section of derive_more::Error
docs.
Seeing if I can replace
thiserror
withderive_more
:gives a compilation error:
whereas
thiserror
has no problem with this:compiles fine.