fix(templates): add error handling

This commit is contained in:
Johannes Kirschbauer
2025-06-11 20:21:49 +02:00
parent 70bc7d3f0c
commit 8c02119ac0

View File

@@ -49,12 +49,15 @@ def machine_template(
[flake_ref, template_selector] = transform_url( [flake_ref, template_selector] = transform_url(
"machine", template_ident, flake=flake "machine", template_ident, flake=flake
) )
# For pretty error messages
printable_template_ref = f"{flake_ref}#{template_selector}"
template_flake = Flake(flake_ref) template_flake = Flake(flake_ref)
template = template_flake.select(template_selector) try:
template = template_flake.select(template_selector)
# For pretty error messages except ClanError as e:
printable_template_ref = f"{flake_ref}#{template_ident}" msg = f"Failed to select template '{template_ident}' from flake '{flake_ref}' (via attribute path: {printable_template_ref})"
raise ClanError(msg) from e
src = template.get("path") src = template.get("path")
if not src: if not src:
@@ -85,7 +88,7 @@ def machine_template(
dst_machine_dir = specific_machine_dir(tmp_machine) dst_machine_dir = specific_machine_dir(tmp_machine)
dst_machine_dir.mkdir(exist_ok=True, parents=True) dst_machine_dir.parent.mkdir(exist_ok=True, parents=True)
copy_from_nixstore(src_path, dst_machine_dir) copy_from_nixstore(src_path, dst_machine_dir)