fix: handle child process exiting with error correctly

This commit is contained in:
Gabriele Musco 2023-09-10 11:22:30 +02:00
commit 245105ba6a
No known key found for this signature in database
GPG key ID: 1068D795C80E51DE
2 changed files with 13 additions and 1 deletions

View file

@ -182,6 +182,9 @@ impl SimpleComponent for BuildWindow {
BuildStatus::Error(_) => label.add_css_class("error"),
_ => {}
}
if status != BuildStatus::Building {
sender.input(Self::Input::UpdateCanClose(true));
}
self.set_build_status(status);
}
Self::Input::UpdateCanClose(val) => {

View file

@ -10,6 +10,7 @@ use std::{
collections::VecDeque,
io::{BufRead, BufReader},
mem,
os::unix::process::ExitStatusExt,
process::{Command, Stdio},
sync::{Arc, Mutex},
thread,
@ -105,7 +106,15 @@ impl Worker for InternalJobWorker {
let stderr_sender = sender.clone();
let stdout_logger = logger_thread!(stdout, stdout_sender);
let stderr_logger = logger_thread!(stderr, stderr_sender);
cmd.wait().expect("Failed to wait for process");
let status = cmd.wait().expect("Failed to wait for process");
if !status.success() {
self.state.lock().unwrap().exit_status = Some(
status
.code()
.unwrap_or_else(|| status.signal().unwrap_or(-1337)),
);
break;
}
stdout_logger.join().expect("Failed to join reader thread");
stderr_logger.join().expect("Failed to join reader thread");
} else {