everscale_types/abi/
error.rs

1//! ABI related error types.
2
3use std::sync::Arc;
4
5/// Error type for ABI version parsing related errors.
6#[derive(Debug, Clone, thiserror::Error)]
7pub enum ParseAbiVersionError {
8    /// Expected a dot separated major and minor components.
9    #[error("invalid format")]
10    InvalidFormat,
11    /// Failed to parse version component as number.
12    #[error("invalid component")]
13    InvalidComponent(#[source] std::num::ParseIntError),
14}
15
16/// Error type for ABI type parsing related errors.
17#[derive(Debug, Clone, thiserror::Error)]
18pub enum ParseAbiTypeError {
19    /// Error while parsing array type.
20    #[error("invalid array type")]
21    InvalidArrayType,
22    /// Error while parsing array length.
23    #[error("invalid array length")]
24    InvalidArrayLength(#[source] std::num::ParseIntError),
25    /// Error while parsing integer bit length.
26    #[error("invalid integer bit length")]
27    InvalidBitLen(#[source] std::num::ParseIntError),
28    /// Error while parsing varint or fixedbytes byte length.
29    #[error("invalid byte length")]
30    InvalidByteLen(#[source] std::num::ParseIntError),
31    /// Expected type to be terminated with ')'.
32    #[error("unterminated inner type")]
33    UnterminatedInnerType,
34    /// Expected value type for map.
35    #[error("map value type not found")]
36    ValueTypeNotFound,
37    /// Invalid ABI type.
38    #[error("unknown type")]
39    UnknownType,
40}
41
42/// Error type for named ABI type parsing related errors.
43#[derive(Debug, Clone, thiserror::Error)]
44pub enum ParseNamedAbiTypeError {
45    /// Error while parsing ABI type.
46    #[error("invalid type `{ty}`: {error}")]
47    InvalidType {
48        /// Parsed ABI type.
49        ty: Box<str>,
50        /// ABI type parsing error.
51        #[source]
52        error: ParseAbiTypeError,
53    },
54    /// Components array was not expected.
55    #[error("unexpected components for `{ty}`")]
56    UnexpectedComponents {
57        /// Parsed ABI type.
58        ty: Box<str>,
59    },
60    /// Expected components array for tuple.
61    #[error("expected components for `{ty}`")]
62    ExpectedComponents {
63        /// Parsed ABI type.
64        ty: Box<str>,
65    },
66}
67
68/// Error type for ABI values unpacking related errors.
69#[derive(Debug, Clone, Eq, PartialEq, thiserror::Error)]
70pub enum AbiError {
71    /// Expected a different value type.
72    #[error("expected ABI type `{expected}`, got `{ty}`")]
73    TypeMismatch {
74        /// A full signature of the expected type.
75        expected: Box<str>,
76        /// A full signature of the received type.
77        ty: Box<str>,
78    },
79    /// More parameters were passed into state init than needed.
80    #[error("unexpected init data parameter `{0}`")]
81    UnexpectedInitDataParam(Arc<str>),
82    /// Field is absent in the init data dictionary.
83    #[error("missing init data field `{0}`")]
84    InitDataFieldNotFound(Arc<str>),
85    /// There are still some unconsumed bits or refs and we did not expect this.
86    #[error("slice was not fully consumed during parsing")]
87    IncompleteDeserialization,
88    /// All cells for `bytes` or `fixedbytes` must have data multiple of 8.
89    #[error("number of bits in a cell is not a multiple of 8")]
90    ExpectedCellWithBytes,
91    /// Expected a valid utf8-encoded string.
92    #[error("invalid string")]
93    InvalidString(#[from] std::str::Utf8Error),
94    /// Invalid length for a fixedarrayN.
95    #[error("expected array of len {expected}, got {len}")]
96    ArraySizeMismatch {
97        /// `N` in `fixedarrayN`.
98        expected: usize,
99        /// Length of the parsed array.
100        len: usize,
101    },
102    /// Invalid length for a fixedbytes{n}.
103    #[error("expected bytes of len {expected}, got {len}")]
104    BytesSizeMismatch {
105        /// `N` in `fixedbytesN`.
106        expected: usize,
107        /// Length of the parsed bytes.
108        len: usize,
109    },
110    /// Address is required for signature for some ABI versions and it was not provided.
111    #[error("an address was expected for signing but was not provided")]
112    AddressNotProvided,
113    /// Expected a different function id while decoding function input.
114    #[error("expected input id 0x{expected:08x}, got 0x{id:08x}")]
115    InputIdMismatch {
116        /// Function input id.
117        expected: u32,
118        /// Id from parsed data.
119        id: u32,
120    },
121    /// Expected a different function id while decoding function output.
122    #[error("expected output id 0x{expected:08x}, got 0x{id:08x}")]
123    OutputIdMismatch {
124        /// Function output id.
125        expected: u32,
126        /// Id from parsed data.
127        id: u32,
128    },
129}