Skip to main content

dpp/errors/consensus/basic/
invalid_identifier_error.rs

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