use jsonrpsee::types::error::{ErrorObject, ErrorObjectOwned};
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Error while querying block: {0}")]
BlockQueryError(Box<dyn std::error::Error + Send>),
#[error("Failed to re-execute the specified block")]
BlockExecutionFailed,
#[error("Failed to extract the proof")]
ProofExtractionFailed,
#[error("Failed to create to compact the witness")]
WitnessCompactionFailed,
#[error(transparent)]
UnsafeRpcCalled(#[from] crate::policy::UnsafeRpcError),
}
const BASE_ERROR: i32 = crate::error::base::DEV;
impl From<Error> for ErrorObjectOwned {
fn from(e: Error) -> Self {
let msg = e.to_string();
match e {
Error::BlockQueryError(_) => ErrorObject::owned(BASE_ERROR + 1, msg, None::<()>),
Error::BlockExecutionFailed => ErrorObject::owned(BASE_ERROR + 3, msg, None::<()>),
Error::WitnessCompactionFailed => ErrorObject::owned(BASE_ERROR + 4, msg, None::<()>),
Error::ProofExtractionFailed => ErrorObject::owned(BASE_ERROR + 5, msg, None::<()>),
Error::UnsafeRpcCalled(e) => e.into(),
}
}
}