fix: exec errors show first stderr line instead of 'exit 1'
This commit is contained in:
parent
996f74b24f
commit
5fd01a423d
1 changed files with 14 additions and 8 deletions
|
|
@ -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}")
|
||||
// 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 {
|
||||
format!("{first_line} · exit {exit_code}")
|
||||
}
|
||||
} 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) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue