ex3-node-error 0.14.1

Underlying error types used over ex3 crates.
Documentation
use std::fmt;

use thiserror::Error;

use crate::{
    def_error_base_on_kind, impl_error_conversion_with_adaptor, impl_error_conversion_with_kind,
};

/// An error with no reason.
#[derive(Error, Debug, Clone, Copy)]
#[error("no reason is provided")]
pub struct SilentError;

/// An error with only a string as the reason.
#[derive(Error, Debug, Clone)]
#[error("{0}")]
pub struct OtherError(String);

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum InternalErrorKind {
    /// Persistent data had corrupted
    DataCorrupted,

    /// Error occurs during database operations
    Database,

    /// Unknown system error
    System,

    /// The feature is disabled or is conflicted with the configuration
    Config,

    /// Canister access error
    Canister,

    /// Other system error
    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 {
    /// Creates an error with only a string as the reason.
    pub fn new<T>(reason: T) -> Self
    where
        T: fmt::Display,
    {
        Self(reason.to_string())
    }
}