Skip to content

Commit

Permalink
feat: handle solc related error in compile_solidity more properly
Browse files Browse the repository at this point in the history
  • Loading branch information
han0110 committed Sep 13, 2023
1 parent 62f147f commit 583c5e9
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub(crate) mod test {
};
use std::{
fmt::{self, Debug, Formatter},
io::Write,
io::{self, Write},
process::{Command, Stdio},
str,
};
Expand All @@ -64,21 +64,30 @@ pub(crate) mod test {
/// # Panics
/// Panics if executable `solc` can not be found, or compilation fails.
pub fn compile_solidity(solidity: impl AsRef<[u8]>) -> Vec<u8> {
let mut cmd = Command::new("solc")
let mut process = match Command::new("solc")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.arg("--bin")
.arg("--via-ir")
.arg("-")
.spawn()
.unwrap();
cmd.stdin
{
Ok(process) => process,
Err(err) if err.kind() == io::ErrorKind::NotFound => {
panic!("Command 'solc' not found");
}
Err(err) => {
panic!("Failed to spwan process with command 'solc':\n{err}");
}
};
process
.stdin
.take()
.unwrap()
.write_all(solidity.as_ref())
.unwrap();
let output = cmd.wait_with_output().unwrap();
let output = process.wait_with_output().unwrap();
let stdout = str::from_utf8(&output.stdout).unwrap();
if let Some(binary) = find_binary(stdout) {
binary
Expand Down

0 comments on commit 583c5e9

Please sign in to comment.