From d18b3ee671b27f765ae771b16ef5d7e2b1ec7c8c Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Mon, 20 Nov 2023 18:14:34 +0100 Subject: [PATCH] catch all exceptions during import of usermodels.py; closes #149 --- src/gui_qt/fit/fitfunction.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gui_qt/fit/fitfunction.py b/src/gui_qt/fit/fitfunction.py index 2b74641..204fcf3 100644 --- a/src/gui_qt/fit/fitfunction.py +++ b/src/gui_qt/fit/fitfunction.py @@ -6,6 +6,7 @@ from nmreval.configs import config_paths from nmreval import models from nmreval.lib.importer import find_models from nmreval.lib.colors import BaseColor, Tab10 +from nmreval.lib.logger import logger from nmreval.utils.text import convert from ..lib.iconloading import get_icon @@ -50,8 +51,14 @@ class QFunctionWidget(QtWidgets.QWidget, Ui_Form): user_defined = [] try: user_defined = find_models(config_paths() / 'usermodels.py') - except FileNotFoundError: - pass + except Exception as e: + import traceback + _ = QtWidgets.QMessageBox.warning( + self, + 'No user functions', + f'Loading user-defined function failed with exception:\n' + f'{"".join(traceback.format_exception(e, limit=1))}') + logger.exception("Invalid usermodels.py", exc_info=e) for model in user_defined: name = model.__name__