1#[macro_export]
2macro_rules! error_parse {
4 ($($t:tt)*) => {
5 $crate::Error::Parse($crate::anyhow!($($t)*))
6 };
7}
8
9#[macro_export]
10macro_rules! error_fetch {
12 ($($t:tt)*) => {
13 $crate::Error::Fetch($crate::anyhow!($($t)*))
14 };
15}
16
17#[derive(Debug, thiserror::Error)]
19#[non_exhaustive]
20pub enum Error {
21 #[error(transparent)]
23 Parse(anyhow::Error),
24 #[error(transparent)]
26 Fetch(anyhow::Error),
27 #[error(transparent)]
28 Io(#[from] std::io::Error),
29 #[error("extra input left")]
31 ExtraInputLeft,
32 #[error("end of input")]
34 EndOfInput,
35 #[error("address index out of bounds")]
37 AddressOutOfBounds,
38 #[error("hash resolution mismatch")]
40 ResolutionMismatch,
41 #[error("data hash mismatch")]
43 DataMismatch,
44 #[error("discriminant overflow")]
46 DiscriminantOverflow,
47 #[error("zero")]
49 Zero,
50 #[error("out of bounds")]
52 OutOfBounds,
53 #[error("length out of bounds")]
55 UnsupportedLength,
56 #[error(transparent)]
58 Utf8(#[from] std::string::FromUtf8Error),
59 #[error("unknown extension")]
61 UnknownExtension,
62 #[error("wrong extension type")]
64 ExtensionType,
65 #[error("not implemented")]
66 Unimplemented,
67 #[error("hash not found in the resolver")]
68 HashNotFound,
69}
70
71impl Error {
72 pub fn parse(e: impl Into<anyhow::Error>) -> Self {
74 Self::Parse(e.into())
75 }
76
77 pub fn fetch(e: impl Into<anyhow::Error>) -> Self {
79 Self::Fetch(e.into())
80 }
81}
82
83pub type Result<T> = std::result::Result<T, Error>;