feat: add solc install error report (#1027)

This commit is contained in:
Matthias Seitz 2022-03-14 12:47:11 +01:00 committed by GitHub
parent 22bc981fd5
commit f6d123241e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 5 deletions

View File

@ -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

View File

@ -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());
}

View File

@ -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 {}",