cast/
errors.rs

1//! Errors for this crate
2
3use foundry_config::Chain;
4use std::fmt;
5
6/// An error thrown when resolving a function via signature failed
7#[derive(Clone, Debug)]
8pub enum FunctionSignatureError {
9    MissingSignature,
10    MissingEtherscan { sig: String },
11    UnknownChain(Chain),
12    MissingToAddress,
13}
14
15impl fmt::Display for FunctionSignatureError {
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        match self {
18            Self::MissingSignature => {
19                writeln!(f, "Function signature must be set")
20            }
21            Self::MissingEtherscan { sig } => {
22                writeln!(f, "Failed to determine function signature for `{sig}`")?;
23                writeln!(f, "To lookup a function signature of a deployed contract by name, a valid ETHERSCAN_API_KEY must be set.")?;
24                write!(f, "\tOr did you mean:\t {sig}()")
25            }
26            Self::UnknownChain(chain) => {
27                write!(f, "Resolving via etherscan requires a known chain. Unknown chain: {chain}")
28            }
29            Self::MissingToAddress => f.write_str("Target address must be set"),
30        }
31    }
32}
33
34impl std::error::Error for FunctionSignatureError {}