Closed mattsse closed 2 weeks ago
would love to take this on sometime this week. :)
Hi @mattsse ! How do I get foundry_compilers
to throw errors when compiling faulty code? I wrote a Solidity code with syntax errors, and expect it to fail, but foundry_compilers
compiles it.
use foundry_compilers::{Project, ProjectPathsConfig};
fn main() {
let project = Project::builder()
.paths(ProjectPathsConfig::hardhat("/home/august/bad_code_solidity_hardhat").unwrap())
.build()
.unwrap();
if let Err(e) = project.compile() {
// The compilation failed, `e` contains the error.
eprintln!("Compilation failed with error: {:?}", e);
}
project.rerun_if_sources_changed();
}
When I do cargo run
I get the following output
Compiling compiler-test v0.1.0 (..../compiler-test)
Finished dev [unoptimized + debuginfo] target(s) in 2.16s
Running `target/debug/compiler-test`
cargo:rerun-if-changed=/home/august/bad_code_solidity_hardhat
Time taken: 2 seconds
ref https://github.com/foundry-rs/foundry/issues/6722
this should improve error formatting and ideally highlight the conflicting versions
https://github.com/foundry-rs/compilers/blob/314c9171c3c09a90dd528c4884bc1b3da569308b/src/resolver/mod.rs#L607-L609