xrpl/models/
exceptions.rs1use core::num::{ParseFloatError, ParseIntError};
4
5use alloc::string::String;
6use thiserror_no_std::Error;
7
8use crate::XRPLSerdeJsonError;
9
10use super::{
11 results::exceptions::XRPLResultException,
12 transactions::exceptions::{
13 XRPLAccountSetException, XRPLClawbackException, XRPLDIDSetException,
14 XRPLNFTokenCancelOfferException, XRPLNFTokenCreateOfferException, XRPLPaymentException,
15 XRPLSignerListSetException, XRPLTransactionException, XRPLXChainClaimException,
16 XRPLXChainCreateBridgeException, XRPLXChainCreateClaimIDException,
17 XRPLXChainModifyBridgeException,
18 },
19};
20
21pub type XRPLModelResult<T, E = XRPLModelException> = core::result::Result<T, E>;
22
23#[derive(Debug, PartialEq, Error)]
24pub enum XRPLModelException {
25 #[error("Expected one of: {}", .0.join(", "))]
27 ExpectedOneOf(&'static [&'static str]),
28 #[error("Invalid field combination: {field} with {other_fields:?}")]
29 InvalidFieldCombination {
30 field: &'static str,
31 other_fields: &'static [&'static str],
32 },
33 #[error("The value of the field `{field:?}` is defined above its maximum (max {max:?}, found {found:?})")]
34 ValueTooHigh { field: String, max: u32, found: u32 },
35 #[error("The value of the field `{field:?}` is defined below its minimum (min {min:?}, found {found:?})")]
36 ValueTooLow { field: String, min: u32, found: u32 },
37 #[error("The value of the field `{field:?}` does not have the correct format (expected {format:?}, found {found:?})")]
38 InvalidValueFormat {
39 field: String,
40 format: String,
41 found: String,
42 },
43 #[error("The value of the field `{field:?}` exceeds its maximum length of characters (max {max:?}, found {found:?})")]
44 ValueTooLong {
45 field: String,
46 max: usize,
47 found: usize,
48 },
49 #[error("The value of the field `{field:?}` is below its minimum length of characters (min {min:?}, found {found:?})")]
50 ValueTooShort {
51 field: String,
52 min: usize,
53 found: usize,
54 },
55 #[error("The value of the field `{field1:?}` is not allowed to be below the value of the field `{field2:?}` (max {field2_val:?}, found {field1_val:?})")]
56 ValueBelowValue {
57 field1: String,
58 field2: String,
59 field1_val: u32,
60 field2_val: u32,
61 },
62 #[error("The value of the field `{field1:?}` is not allowed to be the same as the value of the field `{field2:?}`")]
63 ValueEqualsValue { field1: String, field2: String },
64 #[error("The value of the field `{0:?}` is not allowed to be zero")]
65 ValueZero(String),
66 #[error("If the field `{field1:?}` is defined, the field `{field2:?}` must also be defined")]
67 FieldRequiresField { field1: String, field2: String },
68 #[error("The value of the field `{field:?}` is not a valid value (expected: {expected:?}, found: {found:?})")]
69 InvalidValue {
70 field: String,
71 expected: String,
72 found: String,
73 },
74
75 #[error("Expected field `{0}` is missing")]
76 MissingField(String),
77 #[error("The flags `{flag1:?}` and `{flag2:?}` cannot be set simultaneously")]
78 InvalidFlagCombination { flag1: String, flag2: String },
79
80 #[error("From hex error: {0}")]
81 FromHexError(#[from] hex::FromHexError),
82 #[error("Parse int error: {0}")]
83 ParseIntError(#[from] ParseIntError),
84 #[error("Parse float error: {0}")]
85 ParseFloatError(#[from] ParseFloatError),
86 #[error("serde_json error: {0}")]
87 SerdeJsonError(#[from] XRPLSerdeJsonError),
88 #[error("BigDecimal error: {0}")]
89 BigDecimalError(#[from] bigdecimal::ParseBigDecimalError),
90 #[error("{0}")]
91 XRPLResultError(#[from] XRPLResultException),
92 #[error("{0}")]
93 XRPLTransactionError(#[from] XRPLTransactionException),
94}
95
96#[cfg(feature = "std")]
97impl alloc::error::Error for XRPLModelException {}
98
99impl From<serde_json::Error> for XRPLModelException {
100 fn from(error: serde_json::Error) -> Self {
101 XRPLModelException::SerdeJsonError(error.into())
102 }
103}
104
105impl From<XRPLAccountSetException> for XRPLModelException {
106 fn from(error: XRPLAccountSetException) -> Self {
107 XRPLModelException::XRPLTransactionError(error.into())
108 }
109}
110
111impl From<XRPLDIDSetException> for XRPLModelException {
112 fn from(error: XRPLDIDSetException) -> Self {
113 XRPLModelException::XRPLTransactionError(error.into())
114 }
115}
116
117impl From<XRPLNFTokenCancelOfferException> for XRPLModelException {
118 fn from(error: XRPLNFTokenCancelOfferException) -> Self {
119 XRPLModelException::XRPLTransactionError(error.into())
120 }
121}
122
123impl From<XRPLNFTokenCreateOfferException> for XRPLModelException {
124 fn from(error: XRPLNFTokenCreateOfferException) -> Self {
125 XRPLModelException::XRPLTransactionError(error.into())
126 }
127}
128
129impl From<XRPLPaymentException> for XRPLModelException {
130 fn from(error: XRPLPaymentException) -> Self {
131 XRPLModelException::XRPLTransactionError(error.into())
132 }
133}
134
135impl From<XRPLSignerListSetException> for XRPLModelException {
136 fn from(error: XRPLSignerListSetException) -> Self {
137 XRPLModelException::XRPLTransactionError(error.into())
138 }
139}
140
141impl From<XRPLXChainClaimException> for XRPLModelException {
142 fn from(error: XRPLXChainClaimException) -> Self {
143 XRPLModelException::XRPLTransactionError(error.into())
144 }
145}
146
147impl From<XRPLXChainCreateBridgeException> for XRPLModelException {
148 fn from(error: XRPLXChainCreateBridgeException) -> Self {
149 XRPLModelException::XRPLTransactionError(error.into())
150 }
151}
152
153impl From<XRPLXChainCreateClaimIDException> for XRPLModelException {
154 fn from(error: XRPLXChainCreateClaimIDException) -> Self {
155 XRPLModelException::XRPLTransactionError(error.into())
156 }
157}
158
159impl From<XRPLXChainModifyBridgeException> for XRPLModelException {
160 fn from(error: XRPLXChainModifyBridgeException) -> Self {
161 XRPLModelException::XRPLTransactionError(error.into())
162 }
163}
164
165impl From<XRPLClawbackException> for XRPLModelException {
166 fn from(error: XRPLClawbackException) -> Self {
167 XRPLModelException::XRPLTransactionError(error.into())
168 }
169}