From 21ac1148a31e6a09b78c80ee4f52caa16b9e9884 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Tue, 27 May 2025 01:45:39 +0200 Subject: [PATCH 1/3] chore: clean up error! calls --- crates/compilers/src/artifact_output/mod.rs | 25 +++++++++---------- .../compilers/src/compilers/solc/compiler.rs | 2 +- crates/compilers/src/resolver/mod.rs | 10 +++++--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/crates/compilers/src/artifact_output/mod.rs b/crates/compilers/src/artifact_output/mod.rs index ec2a7d037..ccd079abc 100644 --- a/crates/compilers/src/artifact_output/mod.rs +++ b/crates/compilers/src/artifact_output/mod.rs @@ -625,10 +625,8 @@ pub trait ArtifactOutput { ) -> Result> { let mut artifacts = self.output_to_artifacts(contracts, sources, ctx, layout, primary_profiles); - fs::create_dir_all(&layout.artifacts).map_err(|err| { - error!(dir=?layout.artifacts, "Failed to create artifacts folder"); - SolcIoError::new(err, &layout.artifacts) - })?; + fs::create_dir_all(&layout.artifacts) + .map_err(|err| SolcIoError::new(err, &layout.artifacts))?; artifacts.join_all(&layout.artifacts); artifacts.write_all()?; @@ -1140,16 +1138,17 @@ impl ArtifactOutput for MinimalCombinedArtifactsHardhatFallback { } fn read_cached_artifact(path: &Path) -> Result { - let content = fs::read_to_string(path).map_err(|err| SolcError::io(err, path))?; - if let Ok(a) = serde_json::from_str(&content) { - Ok(a) - } else { - error!("Failed to deserialize compact artifact"); - trace!("Fallback to hardhat artifact deserialization"); - let artifact = serde_json::from_str::(&content)?; - trace!("successfully deserialized hardhat artifact"); - Ok(artifact.into_contract_bytecode()) + #[derive(Deserialize)] + #[serde(untagged)] + enum Artifact { + Compact(CompactContractBytecode), + Hardhat(HardhatArtifact), } + + Ok(match utils::read_json_file::(path)? { + Artifact::Compact(c) => c, + Artifact::Hardhat(h) => h.into_contract_bytecode(), + }) } fn contract_to_artifact( diff --git a/crates/compilers/src/compilers/solc/compiler.rs b/crates/compilers/src/compilers/solc/compiler.rs index 194b37f85..cd4d7559f 100644 --- a/crates/compilers/src/compilers/solc/compiler.rs +++ b/crates/compilers/src/compilers/solc/compiler.rs @@ -54,7 +54,7 @@ pub static RELEASES: std::sync::LazyLock<(svm::Releases, Vec, bool)> = (releases, sorted_versions, true) } Err(err) => { - error!("{:?}", err); + error!("failed to deserialize SVM static RELEASES JSON: {err}"); Default::default() } } diff --git a/crates/compilers/src/resolver/mod.rs b/crates/compilers/src/resolver/mod.rs index 4b0c722c4..b2eedb43a 100644 --- a/crates/compilers/src/resolver/mod.rs +++ b/crates/compilers/src/resolver/mod.rs @@ -917,8 +917,9 @@ impl> Graph { .collect(), ); } else { - error!("failed to resolve versions"); - return Err(SolcError::msg(errors.join("\n"))); + let s = errors.join("\n"); + debug!("failed to resolve versions: {s}"); + return Err(SolcError::msg(s)); } } @@ -960,8 +961,9 @@ impl> Graph { if errors.is_empty() { Ok(resulted_sources) } else { - error!("failed to resolve settings"); - Err(SolcError::msg(errors.join("\n"))) + let s = errors.join("\n"); + debug!("failed to resolve settings: {s}"); + return Err(SolcError::msg(s)); } } From b1413913ce2d4086f49ccc8eee5629e0119472c1 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 27 May 2025 12:38:15 +0200 Subject: [PATCH 2/3] Update crates/compilers/src/resolver/mod.rs --- crates/compilers/src/resolver/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/compilers/src/resolver/mod.rs b/crates/compilers/src/resolver/mod.rs index b2eedb43a..daea8f0b6 100644 --- a/crates/compilers/src/resolver/mod.rs +++ b/crates/compilers/src/resolver/mod.rs @@ -963,7 +963,7 @@ impl> Graph { } else { let s = errors.join("\n"); debug!("failed to resolve settings: {s}"); - return Err(SolcError::msg(s)); + Err(SolcError::msg(s)) } } From fec2bb5c83a676a8eb516c4c60a4ea8f2cc42a67 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Tue, 27 May 2025 13:56:01 +0200 Subject: [PATCH 3/3] fmt --- crates/compilers/src/resolver/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/compilers/src/resolver/mod.rs b/crates/compilers/src/resolver/mod.rs index daea8f0b6..d91592e72 100644 --- a/crates/compilers/src/resolver/mod.rs +++ b/crates/compilers/src/resolver/mod.rs @@ -963,7 +963,7 @@ impl> Graph { } else { let s = errors.join("\n"); debug!("failed to resolve settings: {s}"); - Err(SolcError::msg(s)) + Err(SolcError::msg(s)) } }