I am trying to use the thiserror crate to convert an error into my custom error but I am getting this compilation error message. The error I am trying to implement is the MiddlewareError from the Ethers-rs crate. Below is the compilation error I am getting.
`?` couldn't convert the error to `CFFMError<M>`
the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
required because of the requirements on the impl of
`FromResidual<Result<Infallible, <M as Middleware>::Error>>` for `Result<(), CFFMError<M>>
consider introducing a `where` clause, but there might be an alternative better way to express this requirement: ` where CFFMError<M>: From<<M as Middleware>::Error>`
My error type is defined as
use ethers::prelude::gas_oracle::MiddlewareError;
use ethers::prelude::{AbiError, ContractError};
use ethers::providers::{JsonRpcClient, Middleware, Provider, ProviderError};
use ethers::types::H160;
use thiserror::Error;
use tokio::task::JoinError;
use uniswap_v3_math::error::UniswapV3MathError;
#[derive(Error, Debug)]
pub enum CFFMError<M>
where
M: Middleware,
{
#[error("Middleware error")]
MiddlewareError(#[from] MiddlewareError<M>),
//--snip--
}
When trying to add the following, I get another error saying
conflicting implementations of trait `std::convert::From<error::CFFMError<_>>` for type `error::CFFMError<_>`
conflicting implementation in crate `core`:
- impl<T> From<T> for T;
#[derive(Error, Debug)]
pub enum CFFMError<M>
where
M: Middleware,
{
#[error("Middleware error")]
MiddlewareError(#[from] MiddlewareError<M>),
#[error("some error message")]
OtherMiddlewareError(#[from] M::Error),
//--snip--
}
Can anyone help advise on what do to to resolve this compilation error?