add err output when server failed to start
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
597a681801
commit
b0543aaba9
@ -16,6 +16,9 @@ pub enum Error {
|
||||
#[error("Server exit with `{status}`")]
|
||||
ServerExitWithStatus { status: ExitStatus },
|
||||
|
||||
#[error("Server exit with `{status}` :\n{msg}")]
|
||||
ServerExitWithError { status: ExitStatus, msg: String },
|
||||
|
||||
#[error("Error append during check grammalecte-server status")]
|
||||
ServerCheckStatus(#[source] io::Error),
|
||||
|
||||
@ -91,7 +94,7 @@ impl EmbeddedServer {
|
||||
.arg("-p")
|
||||
.arg(port.to_string())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.map_err(Error::StartServerProcess)?;
|
||||
|
||||
@ -118,6 +121,8 @@ impl Drop for EmbeddedServer {
|
||||
|
||||
mod utils {
|
||||
use super::Error;
|
||||
use std::fmt::Write;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::process::Child;
|
||||
use std::time::Duration;
|
||||
|
||||
@ -151,7 +156,24 @@ mod utils {
|
||||
fn check_server(child: &mut Child) -> Result<(), Error> {
|
||||
match child.try_wait().map_err(Error::ServerCheckStatus)? {
|
||||
None => Ok(()), // Continue
|
||||
Some(status) => Err(Error::ServerExitWithStatus { status }),
|
||||
Some(status) => {
|
||||
if let Some(err) = child.stderr.take() {
|
||||
let mut msg = format!("grammalecte-server exit with `{status}`");
|
||||
writeln!(&mut msg, " :").unwrap();
|
||||
let err = BufReader::new(err);
|
||||
err.lines().for_each(|line| match line {
|
||||
Ok(line) => {
|
||||
writeln!(&mut msg, "\t{}", line).unwrap();
|
||||
}
|
||||
Err(err) => {
|
||||
writeln!(&mut msg, "__{err:?}").unwrap();
|
||||
}
|
||||
});
|
||||
Err(Error::ServerExitWithError { status, msg })
|
||||
} else {
|
||||
Err(Error::ServerExitWithStatus { status })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user