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
use multihash::Multihash;
use thiserror::Error;
pub type Result<T> = core::result::Result<T, BlockError>;
#[derive(Debug, Error)]
pub enum IpldError {
#[error("Expected a boolean.")]
NotBool,
#[error("Expected an integer.")]
NotInteger,
#[error("Expected a float.")]
NotFloat,
#[error("Expected a string.")]
NotString,
#[error("Expected bytes.")]
NotBytes,
#[error("Expected a list.")]
NotList,
#[error("Expected a map.")]
NotMap,
#[error("Expected a cid.")]
NotLink,
#[error("Expected a key.")]
NotKey,
#[error("Index not found.")]
IndexNotFound,
#[error("Key not found.")]
KeyNotFound,
}
impl From<core::convert::Infallible> for IpldError {
fn from(_: core::convert::Infallible) -> Self {
unreachable!();
}
}
#[derive(Debug, Error)]
pub enum BlockError {
#[error("Block size {0} exceeds MAX_BLOCK_SIZE.")]
BlockTooLarge(usize),
#[error("Hash does not match the CID.")]
InvalidHash(Multihash),
#[error("Unsupported codec {0:?}.")]
UnsupportedCodec(cid::Codec),
#[error("Unsupported multihash {0:?}.")]
UnsupportedMultihash(multihash::Code),
#[error("Codec error: {0}")]
CodecError(Box<dyn std::error::Error + Send + Sync>),
#[error("{0}")]
Io(std::io::Error),
#[error("{0}")]
Cid(cid::Error),
#[error("Invalid link.")]
InvalidLink,
}
impl From<std::io::Error> for BlockError {
fn from(err: std::io::Error) -> Self {
Self::Io(err)
}
}
impl From<cid::Error> for BlockError {
fn from(err: cid::Error) -> Self {
Self::Cid(err)
}
}