Skip to content

Commit

Permalink
[user expression] Fix crash and add a log message when the expression…
Browse files Browse the repository at this point in the history
… is not valid, fixes #12852

(cherry picked from commit f7401c9)
  • Loading branch information
slarosa authored and jef-n committed Jun 29, 2015
1 parent daa909f commit 5647056
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions python/user.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import sys
import glob
import traceback

from qgis.core import QgsApplication
from PyQt4.QtCore import QCoreApplication
from qgis.core import QgsApplication, QgsMessageLog

def load_user_expressions(path):
"""
Expand All @@ -14,9 +16,16 @@ def load_user_expressions(path):
for name in names:
if name == "__init__":
continue
# As user expression functions should be registed with qgsfunction
# As user expression functions should be registered with qgsfunction
# just importing the file is enough to get it to load the functions into QGIS
__import__("expressions.{0}".format(name), locals(), globals())
try:
__import__("expressions.{0}".format(name), locals(), globals())
except:
error = traceback.format_exc()
msgtitle = QCoreApplication.translate("UserExpressions", "User expressions")
msg = QCoreApplication.translate("UserExpressions",
"The user expression {0} is not valid".format(name))
QgsMessageLog.logMessage(msg +"\n"+ error, msgtitle, QgsMessageLog.WARNING)


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

0 comments on commit 5647056

Please sign in to comment.