xrpl/core/binarycodec/
exceptions.rs

1//! General XRPL Binary Codec Exceptions.
2
3use crate::utils::exceptions::XRPRangeException;
4
5use super::types::exceptions::XRPLTypeException;
6use thiserror_no_std::Error;
7
8#[derive(Debug, PartialEq, Error)]
9#[non_exhaustive]
10pub enum XRPLBinaryCodecException {
11    #[error("Unexpected parser skip overflow: max: {max}, found: {found}")]
12    UnexpectedParserSkipOverflow { max: usize, found: usize },
13    #[error("Unexpected length prefix range: min: {min}, max: {max}")]
14    UnexpectedLengthPrefixRange { min: usize, max: usize },
15    #[error("Unexpected type code range(min: {min}, max: {max})")]
16    UnexpectedTypeCodeRange { min: usize, max: usize },
17    #[error("Unexpected field code range(min: {min}, max: {max})")]
18    UnexpectedFieldCodeRange { min: usize, max: usize },
19    #[error("Unexpected field id byte range(min: {min}, max: {max})")]
20    UnexpectedFieldIdByteRange { min: usize, max: usize },
21    #[error("Unknown field name")]
22    UnknownFieldName,
23    #[error("Invalid read from bytes value")]
24    InvalidReadFromBytesValue,
25    #[error("Invalid variable length too large: max: {max}")]
26    InvalidVariableLengthTooLarge { max: usize },
27    #[error("Invalid hash length (expected: {expected}, found: {found})")]
28    InvalidHashLength { expected: usize, found: usize },
29    #[error("Invalid path set from value")]
30    InvalidPathSetFromValue,
31    #[error("Try from slice error")]
32    TryFromSliceError,
33    #[error("Field has no associated tag")]
34    FieldHasNoAssiciatedTag,
35    #[error("XAddress tag mismatch")]
36    XAddressTagMismatch,
37    #[error("Field is not account or destination")]
38    FieldIsNotAccountOrDestination,
39    #[error("Try from int error: {0}")]
40    TryFromIntError(#[from] core::num::TryFromIntError),
41    #[error("From utf8 error: {0}")]
42    FromUtf8Error(#[from] alloc::string::FromUtf8Error),
43    #[error("Parse int error: {0}")]
44    ParseIntError(#[from] core::num::ParseIntError),
45    #[error("XRPL Type error: {0}")]
46    XRPLTypeError(#[from] XRPLTypeException),
47    #[error("XRP Range error: {0}")]
48    XRPRangeError(#[from] XRPRangeException),
49}
50
51impl From<core::array::TryFromSliceError> for XRPLBinaryCodecException {
52    fn from(_: core::array::TryFromSliceError) -> Self {
53        XRPLBinaryCodecException::TryFromSliceError
54    }
55}
56
57#[cfg(feature = "std")]
58impl alloc::error::Error for XRPLBinaryCodecException {}