Skip to content

Commit f7401c9

Browse files
committed
[user expression] Fix crash and add a log message when the expression is not valid, fixes #12852
1 parent 51bd0b2 commit f7401c9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

python/user.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
22
import sys
33
import glob
4+
import traceback
45

5-
from qgis.core import QgsApplication
6+
from PyQt4.QtCore import QCoreApplication
7+
from qgis.core import QgsApplication, QgsMessageLog
68

79
def load_user_expressions(path):
810
"""
@@ -14,9 +16,16 @@ def load_user_expressions(path):
1416
for name in names:
1517
if name == "__init__":
1618
continue
17-
# As user expression functions should be registed with qgsfunction
19+
# As user expression functions should be registered with qgsfunction
1820
# just importing the file is enough to get it to load the functions into QGIS
19-
__import__("expressions.{0}".format(name), locals(), globals())
21+
try:
22+
__import__("expressions.{0}".format(name), locals(), globals())
23+
except:
24+
error = traceback.format_exc()
25+
msgtitle = QCoreApplication.translate("UserExpressions", "User expressions")
26+
msg = QCoreApplication.translate("UserExpressions",
27+
"The user expression {0} is not valid".format(name))
28+
QgsMessageLog.logMessage(msg +"\n"+ error, msgtitle, QgsMessageLog.WARNING)
2029

2130

2231
userpythonhome = os.path.join(QgsApplication.qgisSettingsDirPath(), "python")

0 commit comments

Comments
 (0)