Skip to content

Commit

Permalink
When an error occurs while loading a plugin, tag it as a Critical mes…
Browse files Browse the repository at this point in the history
…sage

instead of just a Warning message
  • Loading branch information
nyalldawson committed Apr 16, 2020
1 parent cac5a0c commit 061e858
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions python/utils.py
Expand Up @@ -72,7 +72,7 @@ def showWarning(message, category, filename, lineno, file=None, line=None):
)


def showException(type, value, tb, msg, messagebar=False):
def showException(type, value, tb, msg, messagebar=False, level=Qgis.Warning):
if msg is None:
msg = QCoreApplication.translate('Python', 'An error has occurred while executing Python code:')

Expand All @@ -81,7 +81,7 @@ def showException(type, value, tb, msg, messagebar=False):
logmessage += s.decode('utf-8', 'replace') if hasattr(s, 'decode') else s

title = QCoreApplication.translate('Python', 'Python error')
QgsMessageLog.logMessage(logmessage, title)
QgsMessageLog.logMessage(logmessage, title, level)

try:
blockingdialog = QApplication.instance().activeModalWidget()
Expand Down Expand Up @@ -313,7 +313,7 @@ def loadPlugin(packageName):
return True
except:
msg = QCoreApplication.translate("Python", "Couldn't load plugin '{0}'").format(packageName)
showException(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2], msg, messagebar=True)
showException(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2], msg, messagebar=True, level=Qgis.Critical)
return False


Expand All @@ -336,7 +336,7 @@ def _startPlugin(packageName):
_unloadPluginModules(packageName)
errMsg = QCoreApplication.translate("Python", "Couldn't load plugin '{0}'").format(packageName)
msg = QCoreApplication.translate("Python", "{0} due to an error when calling its classFactory() method").format(errMsg)
showException(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2], msg, messagebar=True)
showException(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2], msg, messagebar=True, level=Qgis.Critical)
return False
return True

Expand All @@ -362,7 +362,7 @@ def startPlugin(packageName):
_unloadPluginModules(packageName)
errMsg = QCoreApplication.translate("Python", "Couldn't load plugin '{0}'").format(packageName)
msg = QCoreApplication.translate("Python", "{0} due to an error when calling its initGui() method").format(errMsg)
showException(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2], msg, messagebar=True)
showException(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2], msg, messagebar=True, level=Qgis.Critical)
return False

end = time.process_time()
Expand All @@ -382,7 +382,7 @@ def startProcessingPlugin(packageName):
del plugins[packageName]
_unloadPluginModules(packageName)
msg = QCoreApplication.translate("Python", "{0} - plugin has no initProcessing() method").format(errMsg)
showException(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2], msg, messagebar=True)
showException(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2], msg, messagebar=True, level=Qgis.Critical)
return False

# initProcessing
Expand Down

0 comments on commit 061e858

Please sign in to comment.