foundry_wallets/
error.rs

1use alloy_primitives::hex::FromHexError;
2use alloy_signer::k256::ecdsa;
3use alloy_signer_ledger::LedgerError;
4use alloy_signer_local::LocalSignerError;
5use alloy_signer_trezor::TrezorError;
6
7#[cfg(feature = "aws-kms")]
8use alloy_signer_aws::AwsSignerError;
9
10#[cfg(feature = "gcp-kms")]
11use alloy_signer_gcp::GcpSignerError;
12
13#[derive(Debug, thiserror::Error)]
14pub enum PrivateKeyError {
15    #[error("Failed to create wallet from private key. Private key is invalid hex: {0}")]
16    InvalidHex(#[from] FromHexError),
17    #[error(
18        "Failed to create wallet from private key. Invalid private key. But env var {0} exists. Is the `$` anchor missing?"
19    )]
20    ExistsAsEnvVar(String),
21}
22
23#[derive(Debug, thiserror::Error)]
24pub enum WalletSignerError {
25    #[error(transparent)]
26    Local(#[from] LocalSignerError),
27    #[error("Failed to decrypt keystore: incorrect password")]
28    IncorrectKeystorePassword,
29    #[error(transparent)]
30    Ledger(#[from] LedgerError),
31    #[error(transparent)]
32    Trezor(#[from] TrezorError),
33    #[error(transparent)]
34    #[cfg(feature = "aws-kms")]
35    Aws(#[from] AwsSignerError),
36    #[error(transparent)]
37    #[cfg(feature = "gcp-kms")]
38    Gcp(#[from] GcpSignerError),
39    #[error(transparent)]
40    Io(#[from] std::io::Error),
41    #[error(transparent)]
42    InvalidHex(#[from] FromHexError),
43    #[error(transparent)]
44    Ecdsa(#[from] ecdsa::Error),
45    #[error("foundry was not built with support for {0} signer")]
46    UnsupportedSigner(&'static str),
47}
48
49impl WalletSignerError {
50    pub fn aws_unsupported() -> Self {
51        Self::UnsupportedSigner("AWS KMS")
52    }
53
54    pub fn gcp_unsupported() -> Self {
55        Self::UnsupportedSigner("Google Cloud KMS")
56    }
57}