lifecycle: surface nixos-container stderr in error + log
This commit is contained in:
parent
58141bdcf0
commit
f6cf4223a4
1 changed files with 17 additions and 4 deletions
|
|
@ -54,13 +54,26 @@ pub async fn list() -> Result<Vec<String>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run(args: &[&str]) -> Result<()> {
|
async fn run(args: &[&str]) -> Result<()> {
|
||||||
let status = Command::new("nixos-container")
|
let out = Command::new("nixos-container")
|
||||||
.args(args)
|
.args(args)
|
||||||
.status()
|
.output()
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("invoke nixos-container {}", args.join(" ")))?;
|
.with_context(|| format!("invoke nixos-container {}", args.join(" ")))?;
|
||||||
if !status.success() {
|
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||||
bail!("nixos-container {} exited with {status}", args.join(" "));
|
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||||
|
if !stdout.trim().is_empty() {
|
||||||
|
tracing::info!(target: "nixos-container", "{}", stdout.trim());
|
||||||
|
}
|
||||||
|
if !stderr.trim().is_empty() {
|
||||||
|
tracing::warn!(target: "nixos-container", "{}", stderr.trim());
|
||||||
|
}
|
||||||
|
if !out.status.success() {
|
||||||
|
bail!(
|
||||||
|
"nixos-container {} failed ({}): {}",
|
||||||
|
args.join(" "),
|
||||||
|
out.status,
|
||||||
|
stderr.trim()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue