From 69bf6ddd0c4fa6d8e8a3de1641429e845280058d Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 8 Apr 2022 16:37:43 +0200 Subject: [PATCH] fix: only notify about unresolved import once (#1125) --- ethers-solc/src/report/mod.rs | 4 ++-- ethers-solc/src/resolver/mod.rs | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ethers-solc/src/report/mod.rs b/ethers-solc/src/report/mod.rs index 79c4dd44..fd549aab 100644 --- a/ethers-solc/src/report/mod.rs +++ b/ethers-solc/src/report/mod.rs @@ -367,9 +367,9 @@ impl Reporter for BasicStdoutReporter { fn on_unresolved_import(&self, import: &Path, remappings: &[Remapping]) { println!( - "Unable to resolve import: \"{}\" with remappings:\n {}", + "Unable to resolve import: \"{}\" with remappings:\n {}", import.display(), - remappings.iter().map(|r| r.to_string()).collect::>().join("\n ") + remappings.iter().map(|r| r.to_string()).collect::>().join("\n ") ); } } diff --git a/ethers-solc/src/resolver/mod.rs b/ethers-solc/src/resolver/mod.rs index a739db59..e5312cd0 100644 --- a/ethers-solc/src/resolver/mod.rs +++ b/ethers-solc/src/resolver/mod.rs @@ -318,6 +318,11 @@ impl Graph { // contains the files and their dependencies let mut nodes = Vec::with_capacity(unresolved.len()); let mut edges = Vec::with_capacity(unresolved.len()); + + // keep track of all unique paths that we failed to resolve to not spam the reporter with + // the same path + let mut unresolved_paths = HashSet::new(); + // now we need to resolve all imports for the source file and those imported from other // locations while let Some((path, node)) = unresolved.pop_front() { @@ -334,11 +339,18 @@ impl Graph { add_node(&mut unresolved, &mut index, &mut resolved_imports, import)?; } Err(err) => { - crate::report::unresolved_import(import.data(), &paths.remappings); - tracing::trace!("failed to resolve import component \"{:?}\"", err) + if unresolved_paths.insert(import.data().to_path_buf()) { + crate::report::unresolved_import(import.data(), &paths.remappings); + } + tracing::trace!( + "failed to resolve import component \"{:?}\" for {:?}", + err, + node.path + ) } }; } + nodes.push(node); edges.push(resolved_imports); }