Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions crates/compilers/src/compilers/resolc/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,14 @@ impl Resolc {
.filter(|x| _resolc_version.is_none_or(|version| version == x.version()))
.collect();

let binary = versions.into_iter().next_back().expect("Can't be empty");
let Some(binary) = versions.into_iter().next_back() else {
let message = if let Some(v) = &_resolc_version {
format!("`resolc` v{v} doesn't exist")
Copy link
Collaborator

@smiasojed smiasojed May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when we set unknown version for solc we get:
Error: Unknown version provided
maybe we should update the error message to Error: Unknown solc version provided?
And for resolc
Error: Unknown resolc version provided
WDYT?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when we set unknown version for solc we get: Error: Unknown version provided maybe we should update the error message to Error: Unknown solc version provided? And for resolc Error: Unknown resolc version provided WDYT?

  • Error: unknown version provided i can't find where this error is produced in code. do you have a link to it?
  • for solc we can have both autodetect and specific, so unsupported solc version can be added as a third message then. WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not have it, I just see such message when using unknown solc version

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not have it, I just see such message when using unknown solc version

i can both come from svm-rs and rvm-rs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it does not make sense to change svm or rvm now

} else {
"No `resolc` versions available.".to_string()
};
return Err(SolcError::Message(message));
};

let binary_info = match binary {
Binary::Remote(binary_info) => binary_info,
Expand Down Expand Up @@ -346,7 +353,9 @@ impl Resolc {
cmd.arg(&solc.solc);
cmd.arg("--standard-json");
let mut child = cmd.spawn().map_err(map_io_err(&self.resolc))?;
let mut stdin = io::BufWriter::new(child.stdin.take().unwrap());
let mut stdin = io::BufWriter::new(
child.stdin.take().ok_or(SolcError::msg("`resolc` `stdin` closed"))?,
);
serde_json::to_writer(&mut stdin, &input)?;
stdin.flush().map_err(map_io_err(&self.resolc))?;
child
Expand Down Expand Up @@ -414,3 +423,23 @@ fn compile_output(output: Output) -> Result<Vec<u8>> {
Err(SolcError::solc_output(&output))
}
}

#[cfg(test)]
#[cfg(feature = "full")]
mod test {
use foundry_compilers_core::error::SolcError;

use super::Resolc;

#[test]
fn not_existing_version() {
let result = Resolc::install(
semver::Version::parse("0.1.0-dev.33").ok().as_ref(),
crate::solc::SolcCompiler::AutoDetect,
)
.expect_err("should fail");
assert!(
matches!(result, SolcError::Message(msg) if msg == "`resolc` v0.1.0-dev.33 doesn't exist")
)
}
}