From 8c02119ac006ee9715c513d3ea0306d19511f8b9 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 11 Jun 2025 20:21:49 +0200 Subject: [PATCH] fix(templates): add error handling --- pkgs/clan-cli/clan_lib/templates/handler.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkgs/clan-cli/clan_lib/templates/handler.py b/pkgs/clan-cli/clan_lib/templates/handler.py index deee2b39f..72d28a627 100644 --- a/pkgs/clan-cli/clan_lib/templates/handler.py +++ b/pkgs/clan-cli/clan_lib/templates/handler.py @@ -49,12 +49,15 @@ def machine_template( [flake_ref, template_selector] = transform_url( "machine", template_ident, flake=flake ) + # For pretty error messages + printable_template_ref = f"{flake_ref}#{template_selector}" template_flake = Flake(flake_ref) - template = template_flake.select(template_selector) - - # For pretty error messages - printable_template_ref = f"{flake_ref}#{template_ident}" + try: + template = template_flake.select(template_selector) + except ClanError as e: + 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") if not src: @@ -85,7 +88,7 @@ def machine_template( 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)