use crate::{
def_error_base_on_kind, impl_error_conversion_with_adaptor, impl_error_conversion_with_kind,
};
use derive_more::Display;
use std::fmt;
use thiserror::Error;
#[derive(Error, Debug, Clone, Copy)]
#[error("no reason is provided")]
pub struct SilentError;
#[derive(Error, Debug, Clone)]
#[error("{0}")]
pub struct OtherError(String);
#[derive(Debug, PartialEq, Eq, Clone, Copy, Display)]
pub enum InternalErrorKind {
CapacityOverflow,
DataCorrupted,
Database,
BlockAssembler,
VM,
MMR,
System,
Config,
Other,
}
def_error_base_on_kind!(InternalError, InternalErrorKind, "Internal error.");
impl_error_conversion_with_kind!(InternalError, crate::ErrorKind::Internal, crate::Error);
impl_error_conversion_with_kind!(OtherError, InternalErrorKind::Other, InternalError);
impl_error_conversion_with_adaptor!(OtherError, InternalError, crate::Error);
impl OtherError {
pub fn new<T>(reason: T) -> Self
where
T: fmt::Display,
{
Self(reason.to_string())
}
}