fix: exec errors show first stderr line instead of 'exit 1'

This commit is contained in:
Helios Agent 2026-03-05 21:31:16 +01:00
parent 996f74b24f
commit 5fd01a423d
No known key found for this signature in database
GPG key ID: C8259547CD8309B5

View file

@ -374,18 +374,24 @@ async fn handle_message(
let mut sh = shell.lock().await;
match sh.run(&command, timeout_ms).await {
Ok((stdout, stderr, exit_code)) => {
let first_line = stdout.trim().lines().next().unwrap_or("").to_string();
let result = if exit_code != 0 {
if first_line.is_empty() {
format!("exit {exit_code}")
} else {
format!("{first_line} · exit {exit_code}")
}
// For errors: use first non-empty stderr line (actual error message),
// ignoring PowerShell boilerplate like "+ CategoryInfo", "In Zeile:", etc.
let err_line = stderr.lines()
.map(|l| l.trim())
.find(|l| !l.is_empty()
&& !l.starts_with("In Zeile:")
&& !l.starts_with("+ ")
&& !l.starts_with("CategoryInfo")
&& !l.starts_with("FullyQualifiedErrorId"))
.unwrap_or("error")
.to_string();
err_line
} else {
first_line // success: just the output, no "exit 0"
// Success: first stdout line, no exit code
stdout.trim().lines().next().unwrap_or("").to_string()
};
display::cmd_done("", "execute", &payload, exit_code == 0, &result);
let _ = stderr;
ClientMessage::ExecResponse { request_id, stdout, stderr, exit_code }
}
Err(e) => {