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