2
0
mirror of https://github.com/frappe/bench.git synced 2024-06-27 11:43:29 +00:00

fix: raise (by default) when exec_cmd fails

This commit is contained in:
Gavin D'souza 2021-11-19 09:16:19 +05:30
parent cd1f526d09
commit 3995b9237b
2 changed files with 8 additions and 2 deletions

View File

@ -20,3 +20,6 @@ class BenchNotFoundError(Exception):
class ValidationError(Exception):
pass
class CannotUpdateReleaseBench(ValidationError):
pass

View File

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