Skip to content

Commit b0123b3

Browse files
committed
Improve build log message when command doesn't exist
Before, it didn't include the actual command that was attempted to run.
1 parent 2ec17ae commit b0123b3

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

objdiff-gui/src/jobs/objdiff.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::{
22
path::{Path, PathBuf},
33
process::Command,
4-
str::from_utf8,
54
sync::mpsc::Receiver,
65
};
76

@@ -91,13 +90,6 @@ pub(crate) fn run_make(config: &BuildConfig, arg: &Path) -> BuildStatus {
9190
..Default::default()
9291
};
9392
};
94-
match run_make_cmd(config, cwd, arg) {
95-
Ok(status) => status,
96-
Err(e) => BuildStatus { success: false, stderr: e.to_string(), ..Default::default() },
97-
}
98-
}
99-
100-
fn run_make_cmd(config: &BuildConfig, cwd: &Path, arg: &Path) -> Result<BuildStatus> {
10193
let make = config.custom_make.as_deref().unwrap_or("make");
10294
let make_args = config.custom_args.as_deref().unwrap_or(&[]);
10395
#[cfg(not(windows))]
@@ -144,15 +136,23 @@ fn run_make_cmd(config: &BuildConfig, cwd: &Path, arg: &Path) -> Result<BuildSta
144136
cmdline.push(' ');
145137
cmdline.push_str(shell_escape::escape(arg.to_string_lossy()).as_ref());
146138
}
147-
let output = command.output().map_err(|e| anyhow!("Failed to execute build: {e}"))?;
148-
let stdout = from_utf8(&output.stdout).context("Failed to process stdout")?;
149-
let stderr = from_utf8(&output.stderr).context("Failed to process stderr")?;
150-
Ok(BuildStatus {
151-
success: output.status.code().unwrap_or(-1) == 0,
152-
cmdline,
153-
stdout: stdout.to_string(),
154-
stderr: stderr.to_string(),
155-
})
139+
let output = match command.output() {
140+
Ok(output) => output,
141+
Err(e) => {
142+
return BuildStatus {
143+
success: false,
144+
cmdline,
145+
stdout: Default::default(),
146+
stderr: e.to_string(),
147+
};
148+
}
149+
};
150+
// Try from_utf8 first to avoid copying the buffer if it's valid, then fall back to from_utf8_lossy
151+
let stdout = String::from_utf8(output.stdout)
152+
.unwrap_or_else(|e| String::from_utf8_lossy(e.as_bytes()).into_owned());
153+
let stderr = String::from_utf8(output.stderr)
154+
.unwrap_or_else(|e| String::from_utf8_lossy(e.as_bytes()).into_owned());
155+
BuildStatus { success: output.status.success(), cmdline, stdout, stderr }
156156
}
157157

158158
fn run_build(

0 commit comments

Comments
 (0)