1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum Error {
5 #[error("UR decoder error ({0})")]
6 UR(String),
7
8 #[error("Bytewords error ({0})")]
9 Bytewords(String),
10
11 #[error("CBOR error ({0})")]
12 Cbor(#[from] dcbor::Error),
13
14 #[error("invalid UR scheme")]
15 InvalidScheme,
16
17 #[error("no UR type specified")]
18 TypeUnspecified,
19
20 #[error("invalid UR type")]
21 InvalidType,
22
23 #[error("UR is not a single-part")]
24 NotSinglePart,
25
26 #[error("expected UR type {0}, but found {1}")]
27 UnexpectedType(String, String),
28}
29
30impl From<ur::ur::Error> for Error {
31 fn from(err: ur::ur::Error) -> Self { Error::UR(err.to_string()) }
32}
33
34impl From<ur::bytewords::Error> for Error {
35 fn from(err: ur::bytewords::Error) -> Self {
36 Error::Bytewords(err.to_string())
37 }
38}
39
40impl From<Error> for String {
41 fn from(err: Error) -> Self { err.to_string() }
42}
43
44impl From<Error> for dcbor::Error {
45 fn from(err: Error) -> Self {
46 match err {
47 Error::Cbor(err) => err,
48 _ => dcbor::Error::msg(err),
49 }
50 }
51}
52
53pub type Result<T> = std::result::Result<T, Error>;