hbkr-rs 0.3.2

Hashblock Key Rotation
Documentation
use thiserror::Error;

use crate::key_manage::KsSignerError;

/// Error values
#[derive(Debug, Error)]
#[error("...")]
pub enum KrError {
    #[error("Inception Error")]
    InceptionError,

    #[error("Deserialize error: {0}")]
    DeserializeError(String),

    #[error("Error while applying event: {0}")]
    SemanticError(String),

    // Signer Error
    #[error("Signer Error")]
    SolRpc(#[from] KsSignerError),

    #[error("Incorrect event digest")]
    IncorrectDigest,

    #[error("Error while applying event: out of order event")]
    EventOutOfOrderError,

    #[error("Error while applying event: duplicate event")]
    EventDuplicateError,

    // Add custom errors here
    #[error("Core Error")]
    CoreErr(#[from] std::num::ParseIntError),

    // Base64 error
    #[error("Base64 Decoding error")]
    Base64DecodingError {
        #[from]
        source: base64::DecodeError,
    },

    // #[error("Base64 Error")]
    // B64Err(#[from] base64::DecodeError),

    // Serde JSON error
    #[error("Serde JSON Error")]
    SerdeJsonErr(#[from] serde_json::Error),

    // Serde CBOR error
    #[error("Serde CBOR Error")]
    SerdeCborErr(#[from] serde_cbor::Error),

    // Serde RMP error
    #[error("Serde RMP Error")]
    SerdeRmpErr(#[from] rmp_serde::encode::Error),
}

// impl Display for KrError {
//     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
//         match self {
//             KrError::InceptionError => formatter.write_str("unexpected end of input"),
//             KrError::DeserializeError(_) => formatter.write_str("unexpected end of input"),
//             KrError::SemanticError(_) => formatter.write_str("unexpected end of input"),
//             KrError::SolRpc(_) => todo!(),
//             KrError::IncorrectDigest => todo!(),
//             KrError::EventOutOfOrderError => todo!(),
//             KrError::EventDuplicateError => todo!(),
//             KrError::CoreErr(_) => todo!(),
//             KrError::Base64DecodingError { source } => todo!(),
//             KrError::SerdeJsonErr(_) => todo!(),
//             KrError::SerdeCborErr(_) => todo!(),
//             KrError::SerdeRmpErr(_) => todo!(),
//             //     Error::Message(msg) => formatter.write_str(msg),
//             //     Error::Eof => formatter.write_str("unexpected end of input"),
//             //     Error::Syntax => formatter.write_str("incorrect syntax"),
//             //     Error::ExpectedBoolean => formatter.write_str("incorrect input: expected boolean"),
//             //     Error::ExpectedInteger => formatter.write_str("incorrect input: expected integer"),
//             //     Error::ExpectedString => formatter.write_str("incorrect input: expected string"),
//             //     Error::ExpectedNull => formatter.write_str("incorrect input: expected null"),
//             //     Error::ExpectedArray => formatter.write_str("incorrect input: expected array"),
//             //     Error::ExpectedArrayComma => {
//             //         formatter.write_str("incorrect input: expected array comma")
//             //     }
//             //     Error::ExpectedArrayEnd => formatter.write_str("incorrect input: expected array end"),
//             //     Error::ExpectedMap => formatter.write_str("incorrect input: expected map"),
//             //     Error::ExpectedMapColon => formatter.write_str("incorrect input: expected map colon"),
//             //     Error::ExpectedMapComma => formatter.write_str("incorrect input: expected map comma"),
//             //     Error::ExpectedMapEnd => formatter.write_str("incorrect input: expected map end"),
//             //     Error::ExpectedEnum => formatter.write_str("incorrect input: expected enum"),
//             //     Error::TrailingCharacters => {
//             //         formatter.write_str("incorrect input: unexpected trailing characters")
//             //     }
//         }
//     }
// }

// impl ser::Error for KrError {
//     fn custom<T: Display>(msg: T) -> Self {
//         KrError::Message(msg.to_string())
//     }
// }

// impl de::Error for KrError {
//     fn custom<T: Display>(msg: T) -> Self {
//         KrError::Message(msg.to_string())
//     }
// }