dpp/errors/
non_consensus_error.rs

1use platform_value::Error as ValueError;
2use thiserror::Error;
3
4use crate::version::FeatureVersion;
5use crate::{
6    CompatibleProtocolVersionIsNotDefinedError, DPPError, InvalidVectorSizeError, SerdeParsingError,
7};
8
9#[derive(Debug, Error)]
10pub enum NonConsensusError {
11    /// Value error
12    #[error("value error: {0}")]
13    ValueError(#[from] ValueError),
14    /// Platform expected some specific versions
15    #[error("non consensus unknown version on {method}, received: {received}")]
16    UnknownVersionMismatch {
17        /// method
18        method: String,
19        /// the allowed versions for this method
20        known_versions: Vec<FeatureVersion>,
21        /// requested core height
22        received: FeatureVersion,
23    },
24    #[error("Unexpected serde parsing error: {0:#}")]
25    SerdeParsingError(SerdeParsingError),
26    #[error(transparent)]
27    CompatibleProtocolVersionIsNotDefinedError(CompatibleProtocolVersionIsNotDefinedError),
28    #[error("SerdeJsonError: {0}")]
29    SerdeJsonError(String),
30    #[error(transparent)]
31    InvalidVectorSizeError(InvalidVectorSizeError),
32    #[error("StateRepositoryFetchError: {0}")]
33    StateRepositoryFetchError(String),
34    #[error("WithdrawalError: {0}")]
35    WithdrawalError(String),
36    #[error("IdentifierCreateError: {0}")]
37    IdentifierCreateError(String),
38    #[error("StateTransitionCreationError: {0}")]
39    StateTransitionCreationError(String),
40    #[error("IdentityPublicKeyCreateError: {0}")]
41    IdentityPublicKeyCreateError(String),
42
43    /// When dynamic `Value` is validated it requires some specific properties to properly work
44    #[error("The property is required: '{property_name}'")]
45    RequiredPropertyError { property_name: String },
46
47    /// Invalid or unsupported object has been used with function/method
48    #[error("Invalid Data: {0}")]
49    InvalidDataProcessedError(String),
50
51    #[error("Failed to create a new instance of '{object_name}'': {details}")]
52    ObjectCreationError {
53        object_name: &'static str,
54        details: String,
55    },
56
57    #[error(transparent)]
58    DPPError(#[from] DPPError),
59
60    #[error(transparent)]
61    Error(#[from] anyhow::Error),
62
63    /// Error
64    #[error("overflow error: {0}")]
65    Overflow(&'static str),
66}
67
68pub mod object_names {
69    pub const STATE_TRANSITION: &str = "State Transition";
70}
71
72impl NonConsensusError {
73    pub fn object_creation_error(object_name: &'static str, error: impl std::fmt::Display) -> Self {
74        Self::ObjectCreationError {
75            object_name,
76            details: format!("{}", error),
77        }
78    }
79}
80
81impl From<SerdeParsingError> for NonConsensusError {
82    fn from(err: SerdeParsingError) -> Self {
83        Self::SerdeParsingError(err)
84    }
85}
86
87impl From<CompatibleProtocolVersionIsNotDefinedError> for NonConsensusError {
88    fn from(err: CompatibleProtocolVersionIsNotDefinedError) -> Self {
89        Self::CompatibleProtocolVersionIsNotDefinedError(err)
90    }
91}
92
93impl From<serde_json::Error> for NonConsensusError {
94    fn from(err: serde_json::Error) -> Self {
95        Self::SerdeJsonError(err.to_string())
96    }
97}
98
99impl From<InvalidVectorSizeError> for NonConsensusError {
100    fn from(err: InvalidVectorSizeError) -> Self {
101        Self::InvalidVectorSizeError(err)
102    }
103}