dpp/data_contract/errors/
contract.rs

1use crate::consensus::basic::data_contract::DocumentTypesAreMissingError;
2use crate::consensus::basic::decode::DecodingError;
3use crate::consensus::basic::BasicError;
4use bincode::{Decode, Encode};
5use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};
6use thiserror::Error;
7
8use crate::consensus::basic::document::InvalidDocumentTypeError;
9use crate::consensus::ConsensusError;
10use crate::data_contract::errors::json_schema_error::JsonSchemaError;
11use crate::ProtocolError;
12
13// @append_only
14#[derive(
15    Error, Debug, PartialEq, PlatformSerialize, PlatformDeserialize, Encode, Decode, Clone,
16)]
17pub enum DataContractError {
18    #[error(transparent)]
19    DecodingContractError(DecodingError),
20
21    #[error(transparent)]
22    DecodingDocumentError(DecodingError),
23
24    #[error(transparent)]
25    InvalidDocumentTypeError(InvalidDocumentTypeError),
26
27    #[error(transparent)]
28    DocumentTypesAreMissingError(DocumentTypesAreMissingError),
29
30    #[error("missing required key: {0}")]
31    MissingRequiredKey(String),
32
33    #[error("field requirement unmet: {0}")]
34    FieldRequirementUnmet(String),
35
36    #[error("regex error: {0}")]
37    RegexError(String),
38
39    #[error("key wrong type error: {0}")]
40    KeyWrongType(String),
41
42    #[error("value wrong type error: {0}")]
43    ValueWrongType(String),
44
45    #[error("invalid uri error: {0}")]
46    InvalidURI(String),
47
48    /// Key wrong bounds error
49    #[error("key out of bounds error: {0}")]
50    KeyWrongBounds(String),
51
52    /// A key value pair must exist
53    #[error("key value must exist: {0}")]
54    KeyValueMustExist(String),
55
56    #[error("value decoding error: {0}")]
57    ValueDecodingError(String),
58
59    #[error("encoding data structure not supported error: {0}")]
60    EncodingDataStructureNotSupported(String),
61
62    #[error("invalid contract structure: {0}")]
63    InvalidContractStructure(String),
64
65    #[error("document type not found: {0}")]
66    DocumentTypeNotFound(String),
67
68    #[error("document type field not found: {0}")]
69    DocumentTypeFieldNotFound(String),
70
71    #[error("reference definition not found error: {0}")]
72    ReferenceDefinitionNotFound(String),
73
74    #[error("document owner id missing error: {0}")]
75    DocumentOwnerIdMissing(String),
76
77    #[error("document id missing error: {0}")]
78    DocumentIdMissing(String),
79
80    #[error("Operation not supported: {0}")]
81    Unsupported(String),
82
83    #[error("Corrupted Serialization: {0}")]
84    CorruptedSerialization(String),
85
86    #[error("Json schema error: {0}")]
87    JsonSchema(JsonSchemaError),
88}
89
90impl From<platform_value::Error> for DataContractError {
91    fn from(value: platform_value::Error) -> Self {
92        DataContractError::ValueDecodingError(format!("{:?}", value))
93    }
94}
95
96impl From<(platform_value::Error, &str)> for DataContractError {
97    fn from(value: (platform_value::Error, &str)) -> Self {
98        DataContractError::ValueDecodingError(format!("{}: {:?}", value.1, value.0))
99    }
100}
101
102impl From<DataContractError> for ConsensusError {
103    fn from(e: DataContractError) -> Self {
104        ConsensusError::BasicError(BasicError::ContractError(e))
105    }
106}