This commit is contained in:
2025-04-05 05:59:51 +02:00
parent 7cdd9f5559
commit 3803a54529
5 changed files with 324 additions and 15 deletions

View File

@@ -185,7 +185,7 @@ fn handle_child_output(mut child: Child, silent: bool) -> Result<CommandResult,
if let Ok(l) = line {
// Print the line if not silent and flush immediately
if !silent_clone {
// Always print stderr, even if silent is true, for error visibility
// Print stderr with error prefix
eprintln!("\x1b[31mERROR: {}\x1b[0m", l); // Red color for errors
std::io::stderr().flush().unwrap_or(());
}
@@ -241,14 +241,8 @@ fn process_command_output(output: Result<Output, std::io::Error>) -> Result<Comm
Ok(out) => {
let stdout = String::from_utf8_lossy(&out.stdout).to_string();
let stderr = String::from_utf8_lossy(&out.stderr).to_string();
// Print stderr if there's any, even for silent execution
if !stderr.is_empty() {
eprintln!("\x1b[31mCommand stderr output:\x1b[0m");
for line in stderr.lines() {
eprintln!("\x1b[31m{}\x1b[0m", line);
}
}
// We'll collect stderr but not print it here
// It will be included in the error message if the command fails
// If the command failed, print a clear error message
if !out.status.success() {
@@ -356,9 +350,12 @@ fn run_script_internal(script: &str, silent: bool) -> Result<CommandResult, RunE
// Execute the script and handle the result
let result = execute_script_internal(&interpreter, &script_path, silent);
// If there was an error, print a clear error message
// If there was an error, print a clear error message only if it's not a CommandFailed error
// (which would already have printed the stderr)
if let Err(ref e) = result {
eprintln!("\x1b[31mScript execution failed: {}\x1b[0m", e);
if !matches!(e, RunError::CommandFailed(_)) {
eprintln!("\x1b[31mScript execution failed: {}\x1b[0m", e);
}
}
result
@@ -485,8 +482,11 @@ impl<'a> RunBuilder<'a> {
Ok(res)
},
Err(e) => {
// Always print the error, even if die is false
eprintln!("\x1b[31mCommand error: {}\x1b[0m", e);
// Print the error only if it's not a CommandFailed error
// (which would already have printed the stderr)
if !matches!(e, RunError::CommandFailed(_)) {
eprintln!("\x1b[31mCommand error: {}\x1b[0m", e);
}
if self.die {
Err(e)