Skip to content

Print stderr when resolc crashes #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Changes from all 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
30 changes: 24 additions & 6 deletions crates/compilers/src/compilers/resolc/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use serde::Serialize;
use std::{
io::{self, Write},
path::{Path, PathBuf},
process::{Command, Output, Stdio},
process::{Child, Command, Output, Stdio},
str::FromStr,
};

Expand Down Expand Up @@ -370,11 +370,20 @@ 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().ok_or(SolcError::msg("`resolc` `stdin` closed"))?,
);
serde_json::to_writer(&mut stdin, &input)?;
stdin.flush().map_err(map_io_err(&self.resolc))?;
let Some(stdin) = child.stdin.take() else {
let err = SolcError::msg("`resolc` `stdin` closed");
return Err(dump_output_to_err(child, err));
};

let mut writer = io::BufWriter::new(stdin);

if let Err(err) = serde_json::to_writer(&mut writer, &input) {
return Err(dump_output_to_err(child, err.into()));
}

if let Err(err) = writer.flush() {
return Err(dump_output_to_err(child, map_io_err(&self.resolc)(err)));
}
child
} else {
cmd.arg("--yul");
Expand All @@ -387,6 +396,7 @@ impl Resolc {
.ok_or_else(|| SolcError::msg("No Yul sources available"))?
));
cmd.arg("--bin");

cmd.spawn().map_err(map_io_err(&self.resolc))?
};

Expand All @@ -406,6 +416,14 @@ impl Resolc {
}
}

fn dump_output_to_err(child: Child, err: SolcError) -> SolcError {
if let Ok(output) = child.wait_with_output() {
SolcError::solc_output(&output)
} else {
err
}
}

fn map_io_err(resolc_path: &Path) -> impl FnOnce(std::io::Error) -> SolcError + '_ {
move |err| SolcError::io(err, resolc_path)
}
Expand Down