From f6d123241e3a74ab6384598f050c4eb85f0638fc Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 14 Mar 2022 12:47:11 +0100 Subject: [PATCH] feat: add solc install error report (#1027) --- ethers-solc/src/compile/mod.rs | 13 ++++++++++--- ethers-solc/src/remappings.rs | 2 +- ethers-solc/src/report.rs | 14 +++++++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ethers-solc/src/compile/mod.rs b/ethers-solc/src/compile/mod.rs index 7f4d48db..6bfbac05 100644 --- a/ethers-solc/src/compile/mod.rs +++ b/ethers-solc/src/compile/mod.rs @@ -372,9 +372,16 @@ impl Solc { pub fn blocking_install(version: &Version) -> std::result::Result<(), svm::SolcVmError> { tracing::trace!("blocking installing solc version \"{}\"", version); crate::report::solc_installation_start(version); - svm::blocking_install(version)?; - crate::report::solc_installation_success(version); - Ok(()) + match svm::blocking_install(version) { + Ok(_) => { + crate::report::solc_installation_success(version); + Ok(()) + } + Err(err) => { + crate::report::solc_installation_error(version, &err.to_string()); + Err(err) + } + } } /// Verify that the checksum for this version of solc is correct. We check against the SHA256 diff --git a/ethers-solc/src/remappings.rs b/ethers-solc/src/remappings.rs index 29ec1f57..9ff4c73e 100644 --- a/ethers-solc/src/remappings.rs +++ b/ethers-solc/src/remappings.rs @@ -661,7 +661,7 @@ mod tests { assert_eq!(relative.path.original(), Path::new(&remapping.path)); assert!(relative.path.parent.is_none()); - let relative = RelativeRemapping::new(remapping.clone(), "/a/b"); + let relative = RelativeRemapping::new(remapping, "/a/b"); assert_eq!(relative.to_relative_remapping(), Remapping::from_str("oz/=c/d/").unwrap()); } diff --git a/ethers-solc/src/report.rs b/ethers-solc/src/report.rs index b7f1a1bc..d7806ca8 100644 --- a/ethers-solc/src/report.rs +++ b/ethers-solc/src/report.rs @@ -99,9 +99,12 @@ pub trait Reporter: 'static { /// Invoked before a new [`Solc`] bin is installed fn on_solc_installation_start(&self, _version: &Version) {} - /// Invoked before a new [`Solc`] bin was successfully installed + /// Invoked after a new [`Solc`] bin was successfully installed fn on_solc_installation_success(&self, _version: &Version) {} + /// Invoked after a [`Solc`] installation failed + fn on_solc_installation_error(&self, _version: &Version, _error: &str) {} + /// Invoked if the import couldn't be resolved with these remappings fn on_unresolved_import(&self, _import: &Path, _remappings: &[Remapping]) {} @@ -166,6 +169,11 @@ pub(crate) fn solc_installation_success(version: &Version) { get_default(|r| r.reporter.on_solc_installation_success(version)); } +#[allow(unused)] +pub(crate) fn solc_installation_error(version: &Version, error: &str) { + get_default(|r| r.reporter.on_solc_installation_error(version, error)); +} + pub(crate) fn unresolved_import(import: &Path, remappings: &[Remapping]) { get_default(|r| r.reporter.on_unresolved_import(import, remappings)); } @@ -308,6 +316,10 @@ impl Reporter for BasicStdoutReporter { println!("Successfully installed solc {}", version); } + fn on_solc_installation_error(&self, version: &Version, error: &str) { + eprintln!("Failed to install solc {}: {}", version, error); + } + fn on_unresolved_import(&self, import: &Path, remappings: &[Remapping]) { println!( "Unable to resolve import: \"{}\" with remappings:\n {}",