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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use std::any::type_name;
use thiserror::Error;
#[derive(Debug, Error)]
#[error("Number larger than {ty}.")]
pub struct NumberOutOfRange {
pub ty: &'static str,
}
impl NumberOutOfRange {
pub fn new<T>() -> Self {
Self {
ty: type_name::<T>(),
}
}
}
#[derive(Debug, Error)]
#[error("Length out of range when decoding {ty}.")]
pub struct LengthOutOfRange {
pub ty: &'static str,
}
impl LengthOutOfRange {
pub fn new<T>() -> Self {
Self {
ty: type_name::<T>(),
}
}
}
#[derive(Debug, Error)]
#[error("Unexpected cbor code `0x{code:x}` when decoding `{ty}`.")]
pub struct UnexpectedCode {
pub code: u8,
pub ty: &'static str,
}
impl UnexpectedCode {
pub fn new<T>(code: u8) -> Self {
Self {
code,
ty: type_name::<T>(),
}
}
}
#[derive(Debug, Error)]
#[error("Unexpected key `{key}` when decoding `{ty}`.")]
pub struct UnexpectedKey {
pub key: String,
pub ty: &'static str,
}
impl UnexpectedKey {
pub fn new<T>(key: String) -> Self {
Self {
key,
ty: type_name::<T>(),
}
}
}
#[derive(Debug, Error)]
#[error("Missing key `{key}` for decoding `{ty}`.")]
pub struct MissingKey {
pub key: &'static str,
pub ty: &'static str,
}
impl MissingKey {
pub fn new<T>(key: &'static str) -> Self {
Self {
key,
ty: type_name::<T>(),
}
}
}
#[derive(Debug, Error)]
#[error("Unkown cbor tag `{0}`.")]
pub struct UnknownTag(pub u8);
#[derive(Debug, Error)]
#[error("Unexpected end of file.")]
pub struct UnexpectedEof;
#[derive(Debug, Error)]
#[error("Invalid Cid prefix: {0}")]
pub struct InvalidCidPrefix(pub u8);