From 81e464ce1f4031475ed7051712b75a75745629e7 Mon Sep 17 00:00:00 2001 From: opi Date: Sun, 28 Aug 2016 23:36:45 +0200 Subject: [PATCH] [enh] Display full exception error message. --- locales/en.json | 4 ++-- src/yunohost/app.py | 13 +++++++++---- src/yunohost/tools.py | 13 +++++++++---- src/yunohost/user.py | 10 +++++----- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/locales/en.json b/locales/en.json index 3a3c8b0b2..dc801a908 100644 --- a/locales/en.json +++ b/locales/en.json @@ -209,8 +209,8 @@ "service_unknown": "Unknown service '{service:s}'", "ssowat_conf_generated": "The SSOwat configuration has been generated", "ssowat_conf_updated": "The SSOwat configuration has been updated", - "ssowat_persistent_conf_read_error": "Error while reading SSOwat persistent configuration", - "ssowat_persistent_conf_write_error": "Error while saving SSOwat persistent configuration", + "ssowat_persistent_conf_read_error": "Error while reading SSOwat persistent configuration: {error:s}", + "ssowat_persistent_conf_write_error": "Error while saving SSOwat persistent configuration: {error:s}", "system_upgraded": "The system has been upgraded", "system_username_exists": "Username already exists in the system users", "unbackup_app": "App '{app:s}' will not be saved", diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 4f4a678d1..b8290f1bb 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -806,9 +806,9 @@ def app_makedefault(auth, app, domain=None): try: with open('/etc/ssowat/conf.json.persistent') as json_conf: ssowat_conf = json.loads(str(json_conf.read())) - except ValueError: + except ValueError as e: raise MoulinetteError(errno.EINVAL, - m18n.n('ssowat_persistent_conf_read_error')) + m18n.n('ssowat_persistent_conf_read_error', error=e.strerror)) except IOError: ssowat_conf = {} @@ -817,8 +817,13 @@ def app_makedefault(auth, app, domain=None): ssowat_conf['redirected_urls'][domain +'/'] = app_domain + app_path - with open('/etc/ssowat/conf.json.persistent', 'w+') as f: - json.dump(ssowat_conf, f, sort_keys=True, indent=4) + try: + with open('/etc/ssowat/conf.json.persistent', 'w+') as f: + json.dump(ssowat_conf, f, sort_keys=True, indent=4) + except IOError as e: + raise MoulinetteError(errno.EPERM, + m18n.n('ssowat_persistent_conf_write_error', error=e.strerror)) + os.system('chmod 644 /etc/ssowat/conf.json.persistent') diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index 7af818a30..906b34e65 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -226,9 +226,9 @@ def tools_postinstall(domain, password, ignore_dyndns=False): try: with open('/etc/ssowat/conf.json.persistent') as json_conf: ssowat_conf = json.loads(str(json_conf.read())) - except ValueError: + except ValueError as e: raise MoulinetteError(errno.EINVAL, - m18n.n('ssowat_persistent_conf_read_error')) + m18n.n('ssowat_persistent_conf_read_error', error=e.strerror)) except IOError: ssowat_conf = {} @@ -237,8 +237,13 @@ def tools_postinstall(domain, password, ignore_dyndns=False): ssowat_conf['redirected_urls']['/'] = domain +'/yunohost/admin' - with open('/etc/ssowat/conf.json.persistent', 'w+') as f: - json.dump(ssowat_conf, f, sort_keys=True, indent=4) + try: + with open('/etc/ssowat/conf.json.persistent', 'w+') as f: + json.dump(ssowat_conf, f, sort_keys=True, indent=4) + except IOError as e: + raise MoulinetteError(errno.EPERM, + m18n.n('ssowat_persistent_conf_write_error', error=e.strerror)) + os.system('chmod 644 /etc/ssowat/conf.json.persistent') diff --git a/src/yunohost/user.py b/src/yunohost/user.py index 51c87f59b..677ba05d4 100644 --- a/src/yunohost/user.py +++ b/src/yunohost/user.py @@ -177,9 +177,9 @@ def user_create(auth, username, firstname, lastname, mail, password, try: with open('/etc/ssowat/conf.json.persistent') as json_conf: ssowat_conf = json.loads(str(json_conf.read())) - except ValueError: + except ValueError as e: raise MoulinetteError(errno.EINVAL, - m18n.n('ssowat_persistent_conf_read_error')) + m18n.n('ssowat_persistent_conf_read_error', error=e.strerror)) except IOError: ssowat_conf = {} @@ -188,9 +188,9 @@ def user_create(auth, username, firstname, lastname, mail, password, try: with open('/etc/ssowat/conf.json.persistent', 'w+') as f: json.dump(ssowat_conf, f, sort_keys=True, indent=4) - except IOError: - raise MoulinetteError(errno.EINVAL, - m18n.n('ssowat_persistent_conf_write_error')) + except IOError as e: + raise MoulinetteError(errno.EPERM, + m18n.n('ssowat_persistent_conf_write_error', error=e.strerror)) if auth.add(rdn, attr_dict):