From 3995b9237b07ef5bef2fbd6a35000b7faa88ab2c Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Fri, 19 Nov 2021 09:16:19 +0530 Subject: [PATCH] fix: raise (by default) when exec_cmd fails --- bench/exceptions.py | 3 +++ bench/utils/__init__.py | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bench/exceptions.py b/bench/exceptions.py index 3002314b..011f0400 100644 --- a/bench/exceptions.py +++ b/bench/exceptions.py @@ -20,3 +20,6 @@ class BenchNotFoundError(Exception): class ValidationError(Exception): pass + +class CannotUpdateReleaseBench(ValidationError): + pass diff --git a/bench/utils/__init__.py b/bench/utils/__init__.py index 1a52291b..9cd363ed 100644 --- a/bench/utils/__init__.py +++ b/bench/utils/__init__.py @@ -15,7 +15,7 @@ import click # imports - module imports from bench import PROJECT_NAME, VERSION -from bench.exceptions import InvalidRemoteException, ValidationError +from bench.exceptions import CommandFailedError, InvalidRemoteException, ValidationError logger = logging.getLogger(PROJECT_NAME) @@ -109,7 +109,7 @@ def pause_exec(seconds=10): print(" " * 40, end="\r") -def exec_cmd(cmd, cwd=".", env=None): +def exec_cmd(cmd, cwd=".", env=None, _raise=True): if env: env.update(os.environ.copy()) @@ -122,6 +122,9 @@ def exec_cmd(cmd, cwd=".", env=None): return_code = subprocess.call(cmd, cwd=cwd, universal_newlines=True, env=env) if return_code: logger.warning(f"{cmd_log} executed with exit code {return_code}") + if _raise: + raise CommandFailedError + return return_code def which(executable: str, raise_err: bool = False) -> str: