1use crate::no_std_prelude::Cow;
10#[cfg(not(feature = "std"))]
11use crate::no_std_prelude::*;
12#[cfg(feature = "serde")]
13use core::num;
14#[cfg(feature = "std")]
15use thiserror::Error;
16
17pub type Result<T> = core::result::Result<T, Error>;
19
20#[cfg_attr(feature = "std", derive(Error))]
22#[derive(Debug)]
23pub enum Error {
24 #[cfg_attr(feature = "std", error("Invalid name: {0}"))]
26 InvalidName(String),
27 #[cfg_attr(feature = "std", error("Invalid data"))]
29 InvalidData,
30 #[cfg(feature = "full-serde")]
32 #[error("Serialization error: {0}")]
33 SerdeJson(#[from] serde_json::Error),
34 #[cfg(feature = "serde")]
36 #[cfg_attr(feature = "std", error("Integer parsing error: {0}"))]
37 ParseInt(#[cfg_attr(feature = "std", from)] num::ParseIntError),
38 #[cfg(feature = "serde")]
40 #[cfg_attr(feature = "std", error("Hex parsing error: {0}"))]
41 Hex(#[cfg_attr(feature = "std", from)] hex::FromHexError),
42 #[cfg_attr(feature = "std", error("{0}"))]
44 Other(Cow<'static, str>),
45}
46
47#[cfg(feature = "serde")]
48impl From<ethereum_types::FromDecStrErr> for Error {
49 fn from(err: ethereum_types::FromDecStrErr) -> Self {
50 use ethereum_types::FromDecStrErr::*;
51 match err {
52 InvalidCharacter => Self::Other(Cow::Borrowed("Uint parse error: InvalidCharacter")),
53 InvalidLength => Self::Other(Cow::Borrowed("Uint parse error: InvalidLength")),
54 }
55 }
56}