From 0133ccd5f72135b9b024a907e375e3de9df3dc84 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Wed, 10 Jan 2024 20:33:41 +0100 Subject: [PATCH] Fixed missing log.BOTH and error_msg at prev refactors --- pkgs/clan-cli/clan_cli/config/machine.py | 3 ++- pkgs/clan-cli/clan_cli/git.py | 22 ++++++--------------- pkgs/clan-cli/clan_cli/machines/machines.py | 1 + pkgs/clan-cli/clan_cli/secrets/generate.py | 3 ++- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/config/machine.py b/pkgs/clan-cli/clan_cli/config/machine.py index 9c406fd30..fa074f38e 100644 --- a/pkgs/clan-cli/clan_cli/config/machine.py +++ b/pkgs/clan-cli/clan_cli/config/machine.py @@ -4,7 +4,7 @@ import re from pathlib import Path from tempfile import NamedTemporaryFile -from clan_cli.cmd import run +from clan_cli.cmd import Log, run from clan_cli.dirs import machine_settings_file, nixpkgs_source, specific_machine_dir from clan_cli.errors import ClanError, ClanHttpError from clan_cli.git import commit_file @@ -65,6 +65,7 @@ def verify_machine_config( cmd, cwd=flake, env=env, + log=Log.BOTH, ) if proc.returncode != 0: return proc.stderr diff --git a/pkgs/clan-cli/clan_cli/git.py b/pkgs/clan-cli/clan_cli/git.py index 977581015..7007413aa 100644 --- a/pkgs/clan-cli/clan_cli/git.py +++ b/pkgs/clan-cli/clan_cli/git.py @@ -1,10 +1,10 @@ from pathlib import Path # from clan_cli.dirs import find_git_repo_root -from clan_cli.errors import ClanCmdError, ClanError +from clan_cli.errors import ClanError from clan_cli.nix import nix_shell -from .cmd import run +from .cmd import Log, run # generic vcs agnostic commit function @@ -42,12 +42,8 @@ def _commit_file_to_git(repo_dir: Path, file_path: Path, commit_message: str) -> ["git", "-C", str(repo_dir), "add", str(file_path)], ) # add the file to the git index - try: - run(cmd) - except ClanCmdError as e: - raise ClanError( - f"Failed to add {file_path} to git repository {repo_dir}:\n{e.cmd.command}\n exited with {e.cmd.returncode}" - ) from e + + run(cmd, log=Log.BOTH, error_msg=f"Failed to add {file_path} file to git index") # check if there is a diff cmd = nix_shell( @@ -72,11 +68,5 @@ def _commit_file_to_git(repo_dir: Path, file_path: Path, commit_message: str) -> str(file_path.relative_to(repo_dir)), ], ) - try: - run( - cmd, - ) - except ClanCmdError as e: - raise ClanError( - f"Failed to commit {file_path} to git repository {repo_dir}:\n{e.cmd.command}\n exited with {e.cmd.returncode}" - ) from e + + run(cmd, error_msg=f"Failed to commit {file_path} to git repository {repo_dir}") diff --git a/pkgs/clan-cli/clan_cli/machines/machines.py b/pkgs/clan-cli/clan_cli/machines/machines.py index a1f0b872b..e640967dd 100644 --- a/pkgs/clan-cli/clan_cli/machines/machines.py +++ b/pkgs/clan-cli/clan_cli/machines/machines.py @@ -18,6 +18,7 @@ def build_machine_data(machine_name: str, clan_dir: Path) -> dict: f'{clan_dir}#clanInternals.machines."{system}"."{machine_name}".config.system.clan.deployment.file' ] ), + error_msg="failed to build machine data", ) return json.loads(Path(proc.stdout.strip()).read_text()) diff --git a/pkgs/clan-cli/clan_cli/secrets/generate.py b/pkgs/clan-cli/clan_cli/secrets/generate.py index 9d07171d0..88f5b02f0 100644 --- a/pkgs/clan-cli/clan_cli/secrets/generate.py +++ b/pkgs/clan-cli/clan_cli/secrets/generate.py @@ -3,7 +3,7 @@ import logging import os import sys -from ..cmd import run +from ..cmd import Log, run from ..machines.machines import Machine log = logging.getLogger(__name__) @@ -19,6 +19,7 @@ def generate_secrets(machine: Machine) -> None: [machine.generate_secrets], env=env, error_msg="failed to generate secrets", + log=Log.BOTH, ) print("successfully generated secrets")