From 37f0c30ddc8cf50a0fc7839026d6e604bff32810 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 11 Mar 2021 03:57:15 +0100 Subject: [PATCH] Inject log_ref into all is_unit_operation failures --- src/yunohost/app.py | 3 +-- src/yunohost/log.py | 10 +++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 613ca21df..f214824aa 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1124,8 +1124,7 @@ def app_install( raise YunohostError( failure_message_with_debug_instructions, - raw_msg=True, - log_ref=operation_logger.name, + raw_msg=True ) # Clean hooks and add new ones diff --git a/src/yunohost/log.py b/src/yunohost/log.py index 1260cd98d..3f5fa8e71 100644 --- a/src/yunohost/log.py +++ b/src/yunohost/log.py @@ -35,7 +35,7 @@ from logging import FileHandler, getLogger, Formatter from moulinette import m18n, msettings from moulinette.core import MoulinetteError -from yunohost.utils.error import YunohostError +from yunohost.utils.error import YunohostError, YunohostValidationError from yunohost.utils.packages import get_ynh_package_version from moulinette.utils.log import getActionLogger from moulinette.utils.filesystem import read_file, read_yaml @@ -635,6 +635,14 @@ class OperationLogger(object): return if error is not None and not isinstance(error, str): error = str(error) + + # When the error happen's in the is_unit_operation try/except, + # we want to inject the log ref in the exception, such that it may be + # transmitted to the webadmin which can then redirect to the appropriate + # log page + if isinstance(error, Exception) and not isinstance(error, YunohostValidationError): + error.log_ref = operation_logger.name + self.ended_at = datetime.utcnow() self._error = error self._success = error is None