codegen: Clean up error handling

Follow-up to 525387f706.
This commit is contained in:
Taiki Endo
2026-11-03 03:15:30 +09:00
parent 8bf69897ab
commit e9605306a6
3 changed files with 27 additions and 34 deletions
+4 -5
View File
@@ -2,13 +2,12 @@
use std::{
fmt, format,
io::{Error, Result},
process::{Command, ExitStatus, Output},
str,
string::{String, ToString as _},
};
use anyhow::{Context as _, Error, Result};
macro_rules! cmd {
($program:expr $(, $arg:expr)* $(,)?) => {{
let mut _cmd = std::process::Command::new($program);
@@ -55,8 +54,8 @@ impl ProcessBuilder {
/// Executes a process, waiting for completion, and mapping non-zero exit
/// status to an error.
pub(crate) fn run(&mut self) -> Result<()> {
let status = self.cmd.status().with_context(|| {
process_error(format!("could not execute process {self}"), None, None)
let status = self.cmd.status().map_err(|e| {
process_error(format!("could not execute process {self}: {e}"), None, None)
})?;
if status.success() {
Ok(())
@@ -151,5 +150,5 @@ fn process_error(mut msg: String, status: Option<ExitStatus>, output: Option<&Ou
}
}
Error::msg(msg)
Error::other(msg)
}