bc_ur/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum Error {
5    #[error("UR decoder error ({0})")]
6    UR(ur::ur::Error),
7
8    #[error("Bytewords error ({0})")]
9    Bytewords(#[from] ur::bytewords::Error),
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) }
32}
33
34impl From<Error> for String {
35    fn from(err: Error) -> Self { err.to_string() }
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>;