From 74222a0e4bb868f3491de11ebb341fafccb43031 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 8 Jul 2020 11:26:01 +0530 Subject: [PATCH] fix(install-app): Handle all exceptions thrown --- frappe/commands/site.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/frappe/commands/site.py b/frappe/commands/site.py index 0f51f21104..530a662886 100755 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -201,16 +201,31 @@ def _reinstall(site, admin_password=None, mariadb_root_username=None, mariadb_ro def install_app(context, apps): "Install a new app to site, supports multiple apps" from frappe.installer import install_app as _install_app + exit_code = 0 + + if not context.sites: + raise SiteNotSpecifiedError + for site in context.sites: frappe.init(site=site) frappe.connect() - try: - for app in apps: + + for app in apps: + try: _install_app(app, verbose=context.verbose) - finally: - frappe.destroy() - if not context.sites: - raise SiteNotSpecifiedError + except frappe.IncompatibleApp as err: + err_msg = ":\n{}".format(err) if str(err) else "" + print("App {} is Incompatible with Site {}{}".format(app, site, err_msg)) + exit_code = 1 + except Exception as err: + err_msg = ":\n{}".format(err if str(err) else frappe.get_traceback()) + print("An error occurred while installing {}{}".format(app, err_msg)) + exit_code = 1 + + frappe.destroy() + + sys.exit(exit_code) + @click.command('list-apps') @pass_context