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