Display raw json content in case of exception

This commit is contained in:
Alexandre Aubin 2019-03-04 18:58:04 +01:00
parent 16245f53d9
commit 88b7d77610
2 changed files with 10 additions and 8 deletions

View file

@ -211,7 +211,7 @@
"good_practices_about_user_password": "You are now about to define a new user password. The password should be at least 8 characters - though it is good practice to use longer password (i.e. a passphrase) and/or to use various kind of characters (uppercase, lowercase, digits and special characters).", "good_practices_about_user_password": "You are now about to define a new user password. The password should be at least 8 characters - though it is good practice to use longer password (i.e. a passphrase) and/or to use various kind of characters (uppercase, lowercase, digits and special characters).",
"hook_exec_failed": "Script execution failed: {path:s}", "hook_exec_failed": "Script execution failed: {path:s}",
"hook_exec_not_terminated": "Script execution hasn\u2019t terminated: {path:s}", "hook_exec_not_terminated": "Script execution hasn\u2019t terminated: {path:s}",
"hook_json_return_error": "Failed to read return from hook {path:s}. Error: {msg:s}", "hook_json_return_error": "Failed to read return from hook {path:s}. Error: {msg:s}. Raw content: {raw_content}",
"hook_list_by_invalid": "Invalid property to list hook by", "hook_list_by_invalid": "Invalid property to list hook by",
"hook_name_unknown": "Unknown hook name '{name:s}'", "hook_name_unknown": "Unknown hook name '{name:s}'",
"installation_complete": "Installation complete", "installation_complete": "Installation complete",

View file

@ -395,15 +395,17 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
elif raise_on_error and returncode != 0: elif raise_on_error and returncode != 0:
raise YunohostError('hook_exec_failed', path=path) raise YunohostError('hook_exec_failed', path=path)
raw_content = None
try: try:
with open(stdreturn, 'r') as f:
with open(stdreturn, 'r') as f: raw_content = f.read()
if f.read() != '': if raw_content != '':
returnjson = read_json(stdreturn) returnjson = read_json(stdreturn)
else: else:
returnjson = {} returnjson = {}
except Exception as e: except Exception as e:
raise YunohostError('hook_json_return_error', path=path, msg=str(e)) raise YunohostError('hook_json_return_error', path=path, msg=str(e),
raw_content=raw_content)
finally: finally:
stdreturndir = os.path.split(stdreturn)[0] stdreturndir = os.path.split(stdreturn)[0]
os.remove(stdreturn) os.remove(stdreturn)