ethabi_next/
errors.rs

1// Copyright 2015-2020 Parity Technologies
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9use anyhow::anyhow;
10use std::{num, string};
11use thiserror::Error;
12
13/// Ethabi result type
14pub type Result<T> = std::result::Result<T, Error>;
15
16/// Ethabi errors
17#[derive(Debug, Error)]
18pub enum Error {
19	/// Invalid entity such as a bad function name.
20	#[error("Invalid name: {0}")]
21	InvalidName(String),
22	/// Invalid data.
23	#[error("Invalid data")]
24	InvalidData,
25	/// Serialization error.
26	#[error("Serialization error: {0}")]
27	SerdeJson(#[from] serde_json::Error),
28	/// Integer parsing error.
29	#[error("Integer parsing error: {0}")]
30	ParseInt(#[from] num::ParseIntError),
31	/// UTF-8 parsing error.
32	#[error("UTF-8 parsing error: {0}")]
33	Utf8(#[from] string::FromUtf8Error),
34	/// Hex string parsing error.
35	#[error("Hex parsing error: {0}")]
36	Hex(#[from] hex::FromHexError),
37	/// Other errors.
38	#[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}