hbkr_rs/errors.rs
1use thiserror::Error;
2
3use crate::key_manage::KsSignerError;
4
5/// Error values
6#[derive(Debug, Error)]
7#[error("...")]
8pub enum KrError {
9 #[error("Inception Error")]
10 InceptionError,
11
12 #[error("Deserialize error: {0}")]
13 DeserializeError(String),
14
15 #[error("Error while applying event: {0}")]
16 SemanticError(String),
17
18 // Signer Error
19 #[error("Signer Error")]
20 SolRpc(#[from] KsSignerError),
21
22 #[error("Incorrect event digest")]
23 IncorrectDigest,
24
25 #[error("Error while applying event: out of order event")]
26 EventOutOfOrderError,
27
28 #[error("Error while applying event: duplicate event")]
29 EventDuplicateError,
30
31 // Add custom errors here
32 #[error("Core Error")]
33 CoreErr(#[from] std::num::ParseIntError),
34
35 // Base64 error
36 #[error("Base64 Decoding error")]
37 Base64DecodingError {
38 #[from]
39 source: base64::DecodeError,
40 },
41
42 // #[error("Base64 Error")]
43 // B64Err(#[from] base64::DecodeError),
44
45 // Serde JSON error
46 #[error("Serde JSON Error")]
47 SerdeJsonErr(#[from] serde_json::Error),
48
49 // Serde CBOR error
50 #[error("Serde CBOR Error")]
51 SerdeCborErr(#[from] serde_cbor::Error),
52
53 // Serde RMP error
54 #[error("Serde RMP Error")]
55 SerdeRmpErr(#[from] rmp_serde::encode::Error),
56}
57
58// impl Display for KrError {
59// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
60// match self {
61// KrError::InceptionError => formatter.write_str("unexpected end of input"),
62// KrError::DeserializeError(_) => formatter.write_str("unexpected end of input"),
63// KrError::SemanticError(_) => formatter.write_str("unexpected end of input"),
64// KrError::SolRpc(_) => todo!(),
65// KrError::IncorrectDigest => todo!(),
66// KrError::EventOutOfOrderError => todo!(),
67// KrError::EventDuplicateError => todo!(),
68// KrError::CoreErr(_) => todo!(),
69// KrError::Base64DecodingError { source } => todo!(),
70// KrError::SerdeJsonErr(_) => todo!(),
71// KrError::SerdeCborErr(_) => todo!(),
72// KrError::SerdeRmpErr(_) => todo!(),
73// // Error::Message(msg) => formatter.write_str(msg),
74// // Error::Eof => formatter.write_str("unexpected end of input"),
75// // Error::Syntax => formatter.write_str("incorrect syntax"),
76// // Error::ExpectedBoolean => formatter.write_str("incorrect input: expected boolean"),
77// // Error::ExpectedInteger => formatter.write_str("incorrect input: expected integer"),
78// // Error::ExpectedString => formatter.write_str("incorrect input: expected string"),
79// // Error::ExpectedNull => formatter.write_str("incorrect input: expected null"),
80// // Error::ExpectedArray => formatter.write_str("incorrect input: expected array"),
81// // Error::ExpectedArrayComma => {
82// // formatter.write_str("incorrect input: expected array comma")
83// // }
84// // Error::ExpectedArrayEnd => formatter.write_str("incorrect input: expected array end"),
85// // Error::ExpectedMap => formatter.write_str("incorrect input: expected map"),
86// // Error::ExpectedMapColon => formatter.write_str("incorrect input: expected map colon"),
87// // Error::ExpectedMapComma => formatter.write_str("incorrect input: expected map comma"),
88// // Error::ExpectedMapEnd => formatter.write_str("incorrect input: expected map end"),
89// // Error::ExpectedEnum => formatter.write_str("incorrect input: expected enum"),
90// // Error::TrailingCharacters => {
91// // formatter.write_str("incorrect input: unexpected trailing characters")
92// // }
93// }
94// }
95// }
96
97// impl ser::Error for KrError {
98// fn custom<T: Display>(msg: T) -> Self {
99// KrError::Message(msg.to_string())
100// }
101// }
102
103// impl de::Error for KrError {
104// fn custom<T: Display>(msg: T) -> Self {
105// KrError::Message(msg.to_string())
106// }
107// }