dpp/errors/consensus/basic/
value_error.rs

1use crate::consensus::basic::BasicError;
2use crate::consensus::ConsensusError;
3use crate::ProtocolError;
4use bincode::{Decode, Encode};
5use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};
6use platform_value::Error as PlatformValueError;
7use thiserror::Error;
8
9#[derive(
10    Error, Debug, Clone, PartialEq, Eq, Encode, Decode, PlatformSerialize, PlatformDeserialize,
11)]
12#[error("{value_error}")]
13#[platform_serialize(unversioned)]
14pub struct ValueError {
15    /*
16
17    DO NOT CHANGE ORDER OF FIELDS WITHOUT INTRODUCING OF NEW VERSION
18
19    */
20    value_error: String,
21}
22
23impl ValueError {
24    pub fn new(value_error: PlatformValueError) -> Self {
25        Self {
26            value_error: value_error.to_string(),
27        }
28    }
29
30    pub fn new_from_string(value_error: String) -> Self {
31        Self { value_error }
32    }
33
34    pub fn value_error(&self) -> &str {
35        &self.value_error
36    }
37}
38impl From<ValueError> for ConsensusError {
39    fn from(err: ValueError) -> Self {
40        Self::BasicError(BasicError::ValueError(err))
41    }
42}
43
44impl From<PlatformValueError> for ValueError {
45    fn from(err: PlatformValueError) -> Self {
46        ValueError::new(err)
47    }
48}