Skip to content

Commit fd6d433

Browse files
committed
fix(forge): improve error messages for etherscan verification failures
1 parent f5932a6 commit fd6d433

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

crates/config/src/etherscan.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ pub enum EtherscanConfigError {
5353
#[error(transparent)]
5454
Unresolved(#[from] UnresolvedEnvVarError),
5555

56-
#[error("No known Etherscan API URL for config{0} with chain `{1}`. Please specify a `url`")]
56+
#[error(
57+
"No known Etherscan API URL for chain `{1}`. To fix this, please:\n
58+
1. Specify a `url` {0}\n
59+
2. Verify the chain `{1}` is correct"
60+
)]
5761
UnknownChain(String, Chain),
5862

5963
#[error("At least one of `url` or `chain` must be present{0}")]
@@ -233,7 +237,7 @@ impl EtherscanConfig {
233237
}),
234238
(Some(chain), None) => ResolvedEtherscanConfig::create(key, chain, api_version)
235239
.ok_or_else(|| {
236-
let msg = alias.map(|a| format!(" `{a}`")).unwrap_or_default();
240+
let msg = alias.map(|a| format!("for `{a}`")).unwrap_or_default();
237241
EtherscanConfigError::UnknownChain(msg, chain)
238242
}),
239243
(None, Some(api_url)) => Ok(ResolvedEtherscanConfig {

crates/config/src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,13 +1429,20 @@ impl Config {
14291429

14301430
// etherscan fallback via API key
14311431
if let Some(key) = self.etherscan_api_key.as_ref() {
1432-
return Ok(ResolvedEtherscanConfig::create(
1432+
match ResolvedEtherscanConfig::create(
14331433
key,
14341434
chain.or(self.chain).unwrap_or_default(),
14351435
default_api_version,
1436-
));
1436+
) {
1437+
Some(config) => return Ok(Some(config)),
1438+
None => {
1439+
return Err(EtherscanConfigError::UnknownChain(
1440+
"".to_string(),
1441+
chain.unwrap_or_default(),
1442+
));
1443+
}
1444+
}
14371445
}
1438-
14391446
Ok(None)
14401447
}
14411448

crates/verify/src/verify.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,11 @@ impl VerifyArgs {
320320
.unwrap_or_default();
321321

322322
if unique_versions.is_empty() {
323-
eyre::bail!("No matching artifact found for {}", contract.name);
323+
eyre::bail!(
324+
"No matching artifact found for {}. This could be due to:\n\
325+
- Compiler version mismatch - the contract was compiled with a different Solidity version than what's being used for verification",
326+
contract.name
327+
);
324328
} else if unique_versions.len() > 1 {
325329
warn!(
326330
"Ambiguous compiler versions found in cache: {}",
@@ -372,7 +376,12 @@ impl VerifyArgs {
372376
.unwrap_or_default();
373377

374378
if profiles.is_empty() {
375-
eyre::bail!("No matching artifact found for {}", contract.name);
379+
eyre::bail!(
380+
"No matching artifact found for {} with compiler version {}. This could be due to:\n\
381+
- Compiler version mismatch - the contract was compiled with a different Solidity version",
382+
contract.name,
383+
version
384+
);
376385
} else if profiles.len() > 1 {
377386
eyre::bail!(
378387
"Ambiguous compilation profiles found in cache: {}, please specify the profile through `--compilation-profile` flag",

0 commit comments

Comments
 (0)