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