get rid of ValueError
This commit is contained in:
@@ -110,10 +110,10 @@ API.register(open_file)
|
||||
def register(self, fn: Callable[..., T]) -> Callable[..., T]:
|
||||
if fn.__name__ in self._registry:
|
||||
msg = f"Function {fn.__name__} already registered"
|
||||
raise ValueError(msg)
|
||||
raise ClanError(msg)
|
||||
if fn.__name__ in self._orig_signature:
|
||||
msg = f"Function {fn.__name__} already registered"
|
||||
raise ValueError(msg)
|
||||
raise ClanError(msg)
|
||||
# make copy of original function
|
||||
self._orig_signature[fn.__name__] = signature(fn)
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ def set_service_instance(
|
||||
|
||||
if module_name not in service_keys:
|
||||
msg = f"{module_name} is not a valid Service attribute. Expected one of {', '.join(service_keys)}."
|
||||
raise ValueError(msg)
|
||||
raise ClanError(msg)
|
||||
|
||||
inventory = load_inventory_json(base_path)
|
||||
target_type = get_args(get_type_hints(Service)[module_name])[1]
|
||||
|
||||
@@ -146,7 +146,7 @@ def run_cmd(programs: list[str], cmd: list[str]) -> list[str]:
|
||||
for program in programs:
|
||||
if not Programs.is_allowed(program):
|
||||
msg = f"Program not allowed: {program}"
|
||||
raise ValueError(msg)
|
||||
raise ClanError(msg)
|
||||
if os.environ.get("IN_NIX_SANDBOX"):
|
||||
return cmd
|
||||
missing_packages = [
|
||||
|
||||
@@ -2,6 +2,10 @@ import subprocess
|
||||
import tempfile
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def is_valid_age_key(secret_key: str) -> bool:
|
||||
# Run the age-keygen command with the -y flag to check the key format
|
||||
result = subprocess.run(
|
||||
@@ -11,7 +15,7 @@ def is_valid_age_key(secret_key: str) -> bool:
|
||||
if result.returncode == 0:
|
||||
return True
|
||||
msg = f"Invalid age key: {secret_key}"
|
||||
raise ValueError(msg)
|
||||
raise Error(msg)
|
||||
|
||||
|
||||
def is_valid_ssh_key(secret_key: str, ssh_pub: str) -> bool:
|
||||
@@ -27,7 +31,7 @@ def is_valid_ssh_key(secret_key: str, ssh_pub: str) -> bool:
|
||||
if result.returncode == 0:
|
||||
if result.stdout != ssh_pub:
|
||||
msg = f"Expected '{ssh_pub}' got '{result.stdout}' for ssh key: {secret_key}"
|
||||
raise ValueError(msg)
|
||||
raise Error(msg)
|
||||
return True
|
||||
msg = f"Invalid ssh key: {secret_key}"
|
||||
raise ValueError(msg)
|
||||
raise Error(msg)
|
||||
|
||||
Reference in New Issue
Block a user