2
0
mirror of https://github.com/frappe/bench.git synced 2024-09-28 06:49:06 +00:00

fix: Raise and handle Exception class

* Instead of sys.exit, raise ValidationError
* Let's not handle BaseException, just Exception
* Use ValidationError instead of invalid syntax raise str
This commit is contained in:
Gavin D'souza 2021-11-13 00:20:05 +05:30
parent e08a12477d
commit c4b8391716
5 changed files with 10 additions and 9 deletions

View File

@ -201,7 +201,7 @@ def get_sites_with_config(bench_path):
"If you want this command to pass, instead of just throwing an error,",
"You may remove the 'strict_nginx' flag from common_site_config.json or set it to 0",
"\n\n")
raise (e)
raise e
else:
print(f"\n\nWARNING: The site config for the site {site} is broken.",
"If you want this command to fail, instead of just showing a warning,",

View File

@ -182,7 +182,7 @@ def reload_supervisor():
def reload_nginx():
try:
exec_cmd(f"sudo {which('nginx')} -t")
except:
except Exception:
raise
service('nginx', 'reload')

View File

@ -191,10 +191,10 @@ def get_bumped_version(version, bump_type):
v.prerelease = ('beta', str(int(v.prerelease[1]) + 1))
else:
raise ("Something wen't wrong while doing a prerelease")
raise ValidationError("Something wen't wrong while doing a prerelease")
else:
raise ("bump_type not amongst [major, minor, patch, prerelease]")
raise ValidationError("bump_type not amongst [major, minor, patch, prerelease]")
return str(v)

View File

@ -239,15 +239,16 @@ def get_bench_name(bench_path):
def set_git_remote_url(git_url, bench_path='.'):
"Set app remote git url"
from bench.app import get_repo_dir
from bench.bench import Bench
app = git_url.rsplit('/', 1)[1].rsplit('.', 1)[0]
if app not in Bench(bench_path).apps:
print(f"No app named {app}")
sys.exit(1)
raise ValidationError(f"No app named {app}")
app_dir = get_repo_dir(app, bench_path=bench_path)
app_dir = bench.app.get_repo_dir(app, bench_path=bench_path)
if os.path.exists(os.path.join(app_dir, '.git')):
exec_cmd(f"git remote set-url upstream {git_url}", cwd=app_dir)

View File

@ -182,7 +182,7 @@ def migrate_env(python, backup=False):
exec_cmd(f'{redis} FLUSHALL')
logger.log('Clearing Redis DataBase...')
exec_cmd(f'{redis} FLUSHDB')
except:
except Exception:
logger.warning('Please ensure Redis Connections are running or Daemonized.')
# Backup venv: restore using `virtualenv --relocatable` if needed
@ -213,7 +213,7 @@ def migrate_env(python, backup=False):
packages_setup = exec_cmd(f'{pvenv} -m pip install -q -U {apps}')
logger.log(f'Migration Successful to {python}')
except:
except Exception:
if venv_creation or packages_setup:
logger.warning('Migration Error')