1use multihash::Multihash;
3use thiserror::Error;
4
5pub type Result<T> = core::result::Result<T, BlockError>;
7
8#[derive(Debug, Error)]
10pub enum IpldError {
11 #[error("Expected a boolean.")]
13 NotBool,
14 #[error("Expected an integer.")]
16 NotInteger,
17 #[error("Expected a float.")]
19 NotFloat,
20 #[error("Expected a string.")]
22 NotString,
23 #[error("Expected bytes.")]
25 NotBytes,
26 #[error("Expected a list.")]
28 NotList,
29 #[error("Expected a map.")]
31 NotMap,
32 #[error("Expected a cid.")]
34 NotLink,
35 #[error("Expected a key.")]
37 NotKey,
38 #[error("Index not found.")]
40 IndexNotFound,
41 #[error("Key not found.")]
43 KeyNotFound,
44}
45
46impl From<core::convert::Infallible> for IpldError {
47 fn from(_: core::convert::Infallible) -> Self {
48 unreachable!();
49 }
50}
51
52#[derive(Debug, Error)]
54pub enum BlockError {
55 #[error("Block size {0} exceeds MAX_BLOCK_SIZE.")]
57 BlockTooLarge(usize),
58 #[error("Hash does not match the CID.")]
60 InvalidHash(Multihash),
61 #[error("Unsupported codec {0:?}.")]
63 UnsupportedCodec(cid::Codec),
64 #[error("Unsupported multihash {0:?}.")]
66 UnsupportedMultihash(multihash::Code),
67 #[error("Codec error: {0}")]
69 CodecError(Box<dyn std::error::Error + Send + Sync>),
70 #[error("{0}")]
72 Io(std::io::Error),
73 #[error("{0}")]
75 Cid(cid::Error),
76 #[error("Invalid link.")]
78 InvalidLink,
79}
80
81impl From<std::io::Error> for BlockError {
82 fn from(err: std::io::Error) -> Self {
83 Self::Io(err)
84 }
85}
86
87impl From<cid::Error> for BlockError {
88 fn from(err: cid::Error) -> Self {
89 Self::Cid(err)
90 }
91}