Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c2e14b3

Browse files
committedFeb 25, 2025
fix(config): prints error when accessing invalid etherscan config
1 parent 4974a08 commit c2e14b3

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed
 

‎crates/config/src/lib.rs

+29-1
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,14 @@ impl Config {
14531453
///
14541454
/// See also [Self::get_etherscan_config_with_chain]
14551455
pub fn get_etherscan_api_key(&self, chain: Option<Chain>) -> Option<String> {
1456-
self.get_etherscan_config_with_chain(chain).ok().flatten().map(|c| c.key)
1456+
self.get_etherscan_config_with_chain(chain)
1457+
.map_err(|e| {
1458+
// `sh_warn!` is a circular dependency, preventing us from using it here.
1459+
eprintln!("Error getting etherscan config: {}", e);
1460+
})
1461+
.ok()
1462+
.flatten()
1463+
.map(|c| c.key)
14571464
}
14581465

14591466
/// Returns the remapping for the project's _src_ directory
@@ -3137,6 +3144,27 @@ mod tests {
31373144
});
31383145
}
31393146

3147+
// any invalid entry invalidates whole [etherscan] sections
3148+
#[test]
3149+
fn test_resolve_etherscan_with_invalid_name() {
3150+
figment::Jail::expect_with(|jail| {
3151+
jail.create_file(
3152+
"foundry.toml",
3153+
r#"
3154+
[etherscan]
3155+
mainnet = { key = "FX42Z3BBJJEWXWGYV2X1CIPRSCN" }
3156+
an_invalid_name = { key = "FX42Z3BBJJEWXWGYV2X1CIPRSCN" }
3157+
"#,
3158+
)?;
3159+
3160+
let config = Config::load().unwrap();
3161+
let etherscan_config = config.get_etherscan_config();
3162+
assert!(etherscan_config.is_none());
3163+
3164+
Ok(())
3165+
});
3166+
}
3167+
31403168
#[test]
31413169
fn test_resolve_rpc_url() {
31423170
figment::Jail::expect_with(|jail| {

0 commit comments

Comments
 (0)
Please sign in to comment.