Fixed missing log.BOTH and error_msg at prev refactors

This commit is contained in:
Qubasa
2024-01-10 20:33:41 +01:00
parent 2ae439ec52
commit 0133ccd5f7
4 changed files with 11 additions and 18 deletions

View File

@@ -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

View File

@@ -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}")

View File

@@ -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())

View File

@@ -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")