cast/
errors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//! Errors for this crate

use foundry_config::Chain;
use std::fmt;

/// An error thrown when resolving a function via signature failed
#[derive(Clone, Debug)]
pub enum FunctionSignatureError {
    MissingSignature,
    MissingEtherscan { sig: String },
    UnknownChain(Chain),
    MissingToAddress,
}

impl fmt::Display for FunctionSignatureError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::MissingSignature => {
                writeln!(f, "Function signature must be set")
            }
            Self::MissingEtherscan { sig } => {
                writeln!(f, "Failed to determine function signature for `{sig}`")?;
                writeln!(f, "To lookup a function signature of a deployed contract by name, a valid ETHERSCAN_API_KEY must be set.")?;
                write!(f, "\tOr did you mean:\t {sig}()")
            }
            Self::UnknownChain(chain) => {
                write!(f, "Resolving via etherscan requires a known chain. Unknown chain: {chain}")
            }
            Self::MissingToAddress => f.write_str("Target address must be set"),
        }
    }
}

impl std::error::Error for FunctionSignatureError {}