1
0
forked from IPKM/nmreval

catch all exceptions during import of usermodels.py; closes #149

This commit is contained in:
Dominik Demuth 2023-11-20 18:14:34 +01:00
parent 64b270d7c1
commit d18b3ee671

View File

@ -6,6 +6,7 @@ from nmreval.configs import config_paths
from nmreval import models from nmreval import models
from nmreval.lib.importer import find_models from nmreval.lib.importer import find_models
from nmreval.lib.colors import BaseColor, Tab10 from nmreval.lib.colors import BaseColor, Tab10
from nmreval.lib.logger import logger
from nmreval.utils.text import convert from nmreval.utils.text import convert
from ..lib.iconloading import get_icon from ..lib.iconloading import get_icon
@ -50,8 +51,14 @@ class QFunctionWidget(QtWidgets.QWidget, Ui_Form):
user_defined = [] user_defined = []
try: try:
user_defined = find_models(config_paths() / 'usermodels.py') user_defined = find_models(config_paths() / 'usermodels.py')
except FileNotFoundError: except Exception as e:
pass 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: for model in user_defined:
name = model.__name__ name = model.__name__