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