everscale_types/
error.rs

1//! Common error types.
2
3/// Error type for cell related errors.
4#[derive(Debug, Clone, Eq, PartialEq, thiserror::Error)]
5pub enum Error {
6    /// There were not enough bits or refs in the cell slice.
7    #[error("cell underflow")]
8    CellUnderflow,
9    /// There were not enough bits or refs capacity in the cell builder.
10    #[error("cell overflow")]
11    CellOverflow,
12    /// Something tried to load a pruned branch cell.
13    #[error("pruned branch access")]
14    PrunedBranchAccess,
15    /// Cell contains invalid descriptor or data.
16    #[error("invalid cell")]
17    InvalidCell,
18    /// Data does not satisfy some constraints.
19    #[error("invalid data")]
20    InvalidData,
21    /// Unknown TLB tag.
22    #[error("invalid tag")]
23    InvalidTag,
24    /// Merkle proof does not contain the root cell.
25    #[error("empty proof")]
26    EmptyProof,
27    /// Tree of cells is too deep.
28    #[error("cell depth overflow")]
29    DepthOverflow,
30    /// Signature check failed.
31    #[error("invalid signature")]
32    InvalidSignature,
33    /// Public key is not in a ed25519 valid range.
34    #[error("invalid public key")]
35    InvalidPublicKey,
36    /// Underlying integer type does not fit into the target type.
37    #[error("underlying integer is too large to fit in target type")]
38    IntOverflow,
39    /// Helper error variant for cancelled operations.
40    #[error("operation cancelled")]
41    Cancelled,
42    /// Presented structure is unbalanced.
43    #[error("unbalanced structure")]
44    Unbalanced,
45}
46
47/// Error type for integer parsing related errors.
48#[derive(Debug, Clone, thiserror::Error)]
49pub enum ParseIntError {
50    /// Error while parsing underlying type.
51    #[error("cannot parse underlying integer")]
52    InvalidString(#[source] std::num::ParseIntError),
53    /// Underlying integer type does not fit into the target type.
54    #[error("underlying integer is too large to fit in target type")]
55    Overflow,
56}
57
58/// Error type for hash bytes parsing related errors.
59#[derive(Debug, Clone, thiserror::Error)]
60pub enum ParseHashBytesError {
61    /// Failed to parse base64 encoded bytes.
62    #[cfg(feature = "base64")]
63    #[error("invalid base64 string")]
64    InvalidBase64(#[from] base64::DecodeSliceError),
65    /// Failed to parse hex encoded bytes.
66    #[error("invalid hex string")]
67    InvalidHex(#[from] hex::FromHexError),
68    /// Error for an unexpected string length.
69    #[error("expected string of 44, 64 or 66 bytes")]
70    UnexpectedStringLength,
71}
72
73/// Error type for address parsing related errors.
74#[derive(Debug, Clone, thiserror::Error)]
75pub enum ParseAddrError {
76    /// Tried to parse an empty string.
77    #[error("cannot parse address from an empty string")]
78    Empty,
79    /// Workchain id is too large.
80    #[error("workchain id is too large to fit in target type")]
81    InvalidWorkchain,
82    /// Invalid account id hex.
83    #[error("cannot parse account id")]
84    InvalidAccountId,
85    /// Too many address parts.
86    #[error("unexpected address part")]
87    UnexpectedPart,
88    /// Unexpected or invalid address format.
89    #[error("invalid address format")]
90    BadFormat,
91}
92
93/// Error type for block id parsing related errors.
94#[derive(Debug, Clone, thiserror::Error)]
95pub enum ParseBlockIdError {
96    /// Tried to parse an empty string.
97    #[error("cannot parse block id from an empty string")]
98    Empty,
99    /// Workchain id is too large.
100    #[error("cannot parse workchain id")]
101    InvalidWorkchain,
102    /// Invalid workchain or shard prefix.
103    #[error("invalid shard id")]
104    InvalidShardIdent,
105    /// Invalid block seqno.
106    #[error("cannot parse block seqno")]
107    InvalidSeqno,
108    /// Invalid root hash hex.
109    #[error("cannot parse root hash")]
110    InvalidRootHash,
111    /// Invalid file hash hex.
112    #[error("cannot parse file hash")]
113    InvalidFileHash,
114    /// Too many block id parts.
115    #[error("unexpected block id part")]
116    UnexpectedPart,
117}
118
119/// Error type for global capability parsing related errors.
120#[derive(Debug, Clone, thiserror::Error)]
121pub enum ParseGlobalCapabilityError {
122    /// Tried to parse an unknown string.
123    #[error("unknown capability")]
124    UnknownCapability,
125}