From 0904c9da60bfffbee71779844adfa1af584321d4 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Tue, 12 Aug 2025 14:18:19 +0700 Subject: [PATCH 1/2] flake.py: Don't hide error messages --- pkgs/clan-cli/clan_lib/flake/flake.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_lib/flake/flake.py b/pkgs/clan-cli/clan_lib/flake/flake.py index 3c1c2145e..096fc6529 100644 --- a/pkgs/clan-cli/clan_lib/flake/flake.py +++ b/pkgs/clan-cli/clan_lib/flake/flake.py @@ -907,7 +907,18 @@ class Flake: ).stdout.strip() ) except ClanCmdError as e: - raise ClanSelectError(flake_identifier=self.identifier, selectors=selectors, cmd_error=e) from e + if "error: attribute" in str(e): + # If the error is about a missing attribute, we raise a ClanSelectError + # with the failed selectors and the flake identifier. + raise ClanSelectError( + flake_identifier=self.identifier, + selectors=selectors, + cmd_error=e, + ) from e + + # If the error is not about a missing attribute, we re-raise it as a ClanCmdError + # to preserve the original error context. + raise if tmp_store := nix_test_store(): build_output = tmp_store.joinpath(*build_output.parts[1:]) From 3c1c6c19426139863feaa4913bce40349583e763 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Tue, 12 Aug 2025 14:23:18 +0700 Subject: [PATCH 2/2] flake.py: Add a custom error message for missing clan export test_clan_create_api: Fix check for SelectCmdError --- pkgs/clan-cli/clan_lib/flake/flake.py | 4 ++++ pkgs/clan-cli/clan_lib/tests/test_create.py | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkgs/clan-cli/clan_lib/flake/flake.py b/pkgs/clan-cli/clan_lib/flake/flake.py index 096fc6529..ed3db7b2b 100644 --- a/pkgs/clan-cli/clan_lib/flake/flake.py +++ b/pkgs/clan-cli/clan_lib/flake/flake.py @@ -907,6 +907,10 @@ class Flake: ).stdout.strip() ) except ClanCmdError as e: + if "error: attribute 'clan' missing" in str(e): + msg = ("This flake does not export the 'clan' attribute. \n" + "Please write 'clan = clan.config' into your flake.nix.") + raise ClanError(msg) from e if "error: attribute" in str(e): # If the error is about a missing attribute, we raise a ClanSelectError # with the failed selectors and the flake identifier. diff --git a/pkgs/clan-cli/clan_lib/tests/test_create.py b/pkgs/clan-cli/clan_lib/tests/test_create.py index b34ab4ac8..5edef1ef7 100644 --- a/pkgs/clan-cli/clan_lib/tests/test_create.py +++ b/pkgs/clan-cli/clan_lib/tests/test_create.py @@ -18,8 +18,8 @@ from clan_cli.vars.generate import get_generators, run_generators from clan_lib.cmd import RunOpts, run from clan_lib.dirs import specific_machine_dir -from clan_lib.errors import ClanError -from clan_lib.flake import ClanSelectError, Flake +from clan_lib.errors import ClanCmdError, ClanError +from clan_lib.flake import Flake from clan_lib.machines.machines import Machine from clan_lib.nix import nix_command from clan_lib.nix_models.clan import ( @@ -278,10 +278,10 @@ def test_clan_create_api( if in_sandbox: # In sandbox: expect build to fail due to network restrictions - with pytest.raises(ClanSelectError) as select_error: + with pytest.raises(ClanCmdError) as select_error: Path(machine.select("config.system.build.toplevel")) # The error should be a select_error without a failed_attr - assert select_error.value.failed_attr is None + assert "nixos-system-test-clan" in str(select_error.value.cmd.stderr) else: # Outside sandbox: build should succeed toplevel_path = Path(machine.select("config.system.build.toplevel"))