Skip to main content

dpp/errors/consensus/basic/
value_error.rs

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