Watch
0
0
Fork
You've already forked hyperhive
0

overlay config .git only when the source has one; record a failed start in the op output

This commit is contained in:
atlas 2026-11-01 12:17:31 +01:00 • committed by mara
commit 23b0c4cd55
2 changed files with 100 additions and 11 deletions

View file

@ -801,6 +801,21 @@ fn make_log_callback(
}
}
/// Put a failed non-streaming op's error into its build-log row, which has no
/// other output: `start` runs through `call`, not the streaming protocol. The
/// error carries `nixos-container`'s stderr.
fn record_failure(
logs: Option<&crate::build_logs::BuildLogs>,
log_id: Option<i64>,
err: &anyhow::Error,
) {
if let (Some(h), Some(id)) = (logs, log_id) {
for line in format!("{err:#}").lines() {
h.append_stderr(id, line);
}
}
}
/// A `create` or `update` asked for without a closure. The
/// public entry points take the closure, so this guards the string dispatch
/// below only.
@ -867,7 +882,13 @@ async fn priv_run_inner(
}
None => Err(missing_toplevel(kind, name)),
},
"start" => crate::priv_client::start_container(name).await,
"start" => {
let started = crate::priv_client::start_container(name).await;
if let Err(e) = &started {
record_failure(logs.as_deref(), log_id, e);
}
started
}
"stop" => crate::priv_client::stop_container(name).await,
"kill" => crate::priv_client::kill_container(name).await,
"destroy" => crate::priv_client::destroy_container(name).await,

View file

@ -514,3 +514,20 @@ fn hive_facts_leave_unset_values_out() {
assert_eq!(facts.egress_no_proxy, None);
assert_eq!(facts.name, None);
}
/// A failed `start` leaves its error in the op's build-log row; without it the
/// row is empty. A missing row id records nothing and does not panic.
#[test]
fn a_failed_start_puts_its_error_in_the_op_output() {
let dir = tempfile::tempdir().expect("tempdir");
let logs = crate::build_logs::BuildLogs::open(dir.path()).expect("open");
let id = logs
.start("updo", "start", "nixos-container start h-updo", None)
.expect("start");
let err = anyhow::anyhow!("nixos-container start h-updo failed (exit status: 1): Job failed");
record_failure(Some(&logs), Some(id), &err);
let full = logs.get_full(id).expect("get").expect("row");
assert!(full.stderr.contains("Job failed"), "{}", full.stderr);
record_failure(Some(&logs), None, &err);
record_failure(None, Some(id), &err);
}