1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use anyhow::anyhow;
use std::{num, string};
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Error)]
pub enum Error {
#[error("Invalid name: {0}")]
InvalidName(String),
#[error("Invalid data")]
InvalidData,
#[error("Serialization error: {0}")]
SerdeJson(#[from] serde_json::Error),
#[error("Integer parsing error: {0}")]
ParseInt(#[from] num::ParseIntError),
#[error("UTF-8 parsing error: {0}")]
Utf8(#[from] string::FromUtf8Error),
#[error("Hex parsing error: {0}")]
Hex(#[from] hex::FromHexError),
#[error("{0}")]
Other(#[from] anyhow::Error),
}
impl From<uint::FromDecStrErr> for Error {
fn from(err: uint::FromDecStrErr) -> Self {
use uint::FromDecStrErr::*;
match err {
InvalidCharacter => anyhow!("Uint parse error: InvalidCharacter"),
InvalidLength => anyhow!("Uint parse error: InvalidLength"),
}
.into()
}
}