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