auto: add some error context when loading first-boot executable

At least to one user in the forum already ran into this IIRC, and most
recently Maximiliano too.

This can happen when e.g. copying example answer files with the
first-boot section, without then passing `--on-first-boot` to
proxmox-auto-install-assistant.

In that case, the user would just get a pretty unhelpful error message:

  ERROR: Autoinstaller setup error: No such file or directory (os error 2)

Attach some context, which points the user directly to the corresponding
setting / answer file section.

Reported-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
Link: https://lore.proxmox.com/20250408095450.421071-1-c.heiss@proxmox.com
This commit is contained in:
Christoph Heiss 2025-04-08 11:54:43 +02:00 committed by Thomas Lamprecht
parent 4b5db269ec
commit 9143452ddb

View File

@ -1,4 +1,4 @@
use anyhow::{Result, bail, format_err};
use anyhow::{Context, Result, bail, format_err};
use log::{LevelFilter, error, info};
use std::{
env,
@ -47,7 +47,9 @@ fn setup_first_boot_executable(first_boot: &FirstBootHookInfo) -> Result<()> {
}
}
FirstBootHookSourceMode::FromIso => {
Some(fs::read(format!("/cdrom/{FIRST_BOOT_EXEC_NAME}"))?)
let content = fs::read(format!("/cdrom/{FIRST_BOOT_EXEC_NAME}"))
.context("failed loading first-boot executable from ISO (was ISO prepared with `--on-first-boot` specified?)")?;
Some(content)
}
};
@ -115,7 +117,7 @@ fn main() -> ExitCode {
let (answer, udevadm_info) = match auto_installer_setup(in_test_mode) {
Ok(result) => result,
Err(err) => {
error!("Autoinstaller setup error: {err}");
error!("Autoinstaller setup error: {err:?}");
return ExitCode::FAILURE;
}
};