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
//! Common error types.

/// Error type for cell related errors.
#[derive(Debug, Clone, thiserror::Error)]
pub enum Error {
    /// There were not enough bits or refs in the cell slice.
    #[error("cell underflow")]
    CellUnderflow,
    /// There were not enough bits or refs capacity in the cell builder.
    #[error("cell overflow")]
    CellOverflow,
    /// Something tried to load a pruned branch cell.
    #[error("pruned branch access")]
    PrunedBranchAccess,
}

/// Error type for integer parsing related errors.
#[derive(Debug, Clone, thiserror::Error)]
pub enum ParseIntError {
    /// Error while parsing underlying type.
    #[error("cannot parse underlying integer")]
    InvalidString(#[source] std::num::ParseIntError),
    /// Underlying integer type does not fit into the target type.
    #[error("underlying integer is too large to fin in target type")]
    Overflow,
}

/// Error type for address parsing related errors.
#[derive(Debug, Clone, thiserror::Error)]
pub enum ParseAddrError {
    /// Tried to parse an empty string.
    #[error("cannot parse address from an empty string")]
    Empty,
    /// Workchain id is too large.
    #[error("workchain id is too large to fit in target type")]
    InvalidWorkchain,
    /// Invalid account id hex.
    #[error("cannot parse account id")]
    InvalidAccountId,
    /// Too many address parts.
    #[error("unexpected address part")]
    UnexpectedPart,
}

/// Error type for block id parsing related errors.
#[derive(Debug, Clone, thiserror::Error)]
pub enum ParseBlockIdError {
    /// Tried to parse an empty string.
    #[error("cannot parse block id from an empty string")]
    Empty,
    /// Workchain id is too large.
    #[error("cannot parse workchain id")]
    InvalidWorkchain,
    /// Invalid workchain or shard prefix.
    #[error("invalid shard id")]
    InvalidShardIdent,
    /// Invalid block seqno.
    #[error("cannot parse block seqno")]
    InvalidSeqno,
    /// Invalid root hash hex.
    #[error("cannot parse root hash")]
    InvalidRootHash,
    /// Invalid file hash hex.
    #[error("cannot parse file hash")]
    InvalidFileHash,
    /// Too many block id parts.
    #[error("unexpected block id part")]
    UnexpectedPart,
}