bc_ur/
error.rs

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