pink_web3/contract/
error.rs

1//! Contract call/query error.
2use crate::prelude::*;
3
4use crate::error::Error as ApiError;
5use derive_more::{Display, From};
6use ethabi::Error as EthError;
7
8/// Contract error.
9#[derive(Debug, Display, From)]
10pub enum Error {
11    /// invalid output type requested by the caller
12    #[display(fmt = "Invalid output type: {}", _0)]
13    InvalidOutputType(String),
14    /// eth abi error
15    #[display(fmt = "Abi error: {:?}", _0)]
16    Abi(EthError),
17    /// Rpc error
18    #[display(fmt = "Api error: {}", _0)]
19    Api(ApiError),
20    /// An error during deployment.
21    #[display(fmt = "Deployment error: {}", _0)]
22    Deployment(crate::contract::deploy::Error),
23    /// An error during Json decode.
24    #[display(fmt = "Deployment error: {}", _0)]
25    #[from(ignore)]
26    JsonDecode(String),
27    /// Contract does not support this interface.
28    InterfaceUnsupported,
29}
30
31#[cfg(feature = "std")]
32impl std::error::Error for Error {
33    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
34        match *self {
35            Error::InvalidOutputType(_) => None,
36            Error::Abi(ref e) => Some(e),
37            Error::Api(ref e) => Some(e),
38            Error::Deployment(ref e) => Some(e),
39            Error::InterfaceUnsupported => None,
40            Error::JsonDecode(_) => None,
41        }
42    }
43}
44
45pub mod deploy {
46    use crate::{error::Error as ApiError, types::H256};
47    use derive_more::{Display, From};
48
49    /// Contract deployment error.
50    #[derive(Debug, Display, From)]
51    pub enum Error {
52        /// eth abi error
53        #[display(fmt = "Abi error: {:?}", _0)]
54        Abi(ethabi::Error),
55        /// Rpc error
56        #[display(fmt = "Api error: {}", _0)]
57        Api(ApiError),
58        /// Contract deployment failed
59        #[display(fmt = "Failure during deployment.Tx hash: {:?}", _0)]
60        ContractDeploymentFailure(H256),
61    }
62
63    #[cfg(feature = "std")]
64    impl std::error::Error for Error {
65        fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
66            match *self {
67                Error::Abi(ref e) => Some(e),
68                Error::Api(ref e) => Some(e),
69                Error::ContractDeploymentFailure(_) => None,
70            }
71        }
72    }
73}