diff --git a/pkgs/clan-cli/clan_lib/flake/flake.py b/pkgs/clan-cli/clan_lib/flake/flake.py index 3c1c2145e..ed3db7b2b 100644 --- a/pkgs/clan-cli/clan_lib/flake/flake.py +++ b/pkgs/clan-cli/clan_lib/flake/flake.py @@ -907,7 +907,22 @@ class Flake: ).stdout.strip() ) except ClanCmdError as e: - raise ClanSelectError(flake_identifier=self.identifier, selectors=selectors, cmd_error=e) from 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. + 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:]) diff --git a/pkgs/clan-cli/clan_lib/tests/test_create.py b/pkgs/clan-cli/clan_lib/tests/test_create.py index 4e99a4bce..ae8b67354 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.network.network import get_network_overview, networks_from_flake from clan_lib.nix import nix_command @@ -284,10 +284,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"))