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<()> {
|
||||
let status = Command::new("nixos-container")
|
||||
let out = Command::new("nixos-container")
|
||||
.args(args)
|
||||
.status()
|
||||
.output()
|
||||
.await
|
||||
.with_context(|| format!("invoke nixos-container {}", args.join(" ")))?;
|
||||
if !status.success() {
|
||||
bail!("nixos-container {} exited with {status}", args.join(" "));
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue