1use std::any::type_name;
3use thiserror::Error;
4
5#[derive(Debug, Error)]
7#[error("Number larger than {ty}.")]
8pub struct NumberOutOfRange {
9 pub ty: &'static str,
11}
12
13impl NumberOutOfRange {
14 pub fn new<T>() -> Self {
16 Self {
17 ty: type_name::<T>(),
18 }
19 }
20}
21
22#[derive(Debug, Error)]
24#[error("Number not minimally encoded.")]
25pub struct NumberNotMinimal;
26
27#[derive(Debug, Error)]
29#[error("Length out of range when decoding {ty}.")]
30pub struct LengthOutOfRange {
31 pub ty: &'static str,
33}
34
35impl LengthOutOfRange {
36 pub fn new<T>() -> Self {
38 Self {
39 ty: type_name::<T>(),
40 }
41 }
42}
43
44#[derive(Debug, Error)]
46#[error("Unexpected cbor code `0x{code:x}` when decoding `{ty}`.")]
47pub struct UnexpectedCode {
48 pub code: u8,
50 pub ty: &'static str,
52}
53
54impl UnexpectedCode {
55 pub fn new<T>(code: u8) -> Self {
57 Self {
58 code,
59 ty: type_name::<T>(),
60 }
61 }
62}
63
64#[derive(Debug, Error)]
66#[error("Unexpected key `{key}` when decoding `{ty}`.")]
67pub struct UnexpectedKey {
68 pub key: String,
70 pub ty: &'static str,
72}
73
74impl UnexpectedKey {
75 pub fn new<T>(key: String) -> Self {
77 Self {
78 key,
79 ty: type_name::<T>(),
80 }
81 }
82}
83
84#[derive(Debug, Error)]
86#[error("Missing key `{key}` for decoding `{ty}`.")]
87pub struct MissingKey {
88 pub key: &'static str,
90 pub ty: &'static str,
92}
93
94impl MissingKey {
95 pub fn new<T>(key: &'static str) -> Self {
97 Self {
98 key,
99 ty: type_name::<T>(),
100 }
101 }
102}
103
104#[derive(Debug, Error)]
106#[error("Unknown cbor tag `{0}`.")]
107pub struct UnknownTag(pub u64);
108
109#[derive(Debug, Error)]
111#[error("Unexpected end of file.")]
112pub struct UnexpectedEof;
113
114#[derive(Debug, Error)]
116#[error("Invalid Cid prefix: {0}")]
117pub struct InvalidCidPrefix(pub u8);
118
119#[derive(Debug, Error)]
121#[error("Duplicate map key.")]
122pub struct DuplicateKey;