libipld_raw_cbor/
error.rs1use 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("Length out of range when decoding {ty}.")]
25pub struct LengthOutOfRange {
26 pub ty: &'static str,
28}
29
30impl LengthOutOfRange {
31 pub fn new<T>() -> Self {
33 Self {
34 ty: type_name::<T>(),
35 }
36 }
37}
38
39#[derive(Debug, Error)]
41#[error("Unexpected cbor code `0x{code:x}` when decoding `{ty}`.")]
42pub struct UnexpectedCode {
43 pub code: u8,
45 pub ty: &'static str,
47}
48
49impl UnexpectedCode {
50 pub fn new<T>(code: u8) -> Self {
52 Self {
53 code,
54 ty: type_name::<T>(),
55 }
56 }
57}
58
59#[derive(Debug, Error)]
61#[error("Unexpected key `{key}` when decoding `{ty}`.")]
62pub struct UnexpectedKey {
63 pub key: String,
65 pub ty: &'static str,
67}
68
69impl UnexpectedKey {
70 pub fn new<T>(key: String) -> Self {
72 Self {
73 key,
74 ty: type_name::<T>(),
75 }
76 }
77}
78
79#[derive(Debug, Error)]
81#[error("Missing key `{key}` for decoding `{ty}`.")]
82pub struct MissingKey {
83 pub key: &'static str,
85 pub ty: &'static str,
87}
88
89impl MissingKey {
90 pub fn new<T>(key: &'static str) -> Self {
92 Self {
93 key,
94 ty: type_name::<T>(),
95 }
96 }
97}
98
99#[derive(Debug, Error)]
101#[error("Unkown cbor tag `{0}`.")]
102pub struct UnknownTag(pub u8);
103
104#[derive(Debug, Error)]
106#[error("Unexpected end of file.")]
107pub struct UnexpectedEof;
108
109#[derive(Debug, Error)]
111#[error("Invalid Cid prefix: {0}")]
112pub struct InvalidCidPrefix(pub u8);