Convert two common plugin errors from unhandled exceptions to warnings.

Missing translation for the current primary locale.
Import failure because of some missing dependency.

Note that these handlers can be overridded in the module itself; this is just a fallback.
This commit is contained in:
John Ralls 2014-03-07 16:20:24 -08:00
parent 58d150ebc8
commit 80c58f46d3

View File

@ -41,6 +41,9 @@ from __future__ import print_function
import os
import sys
import re
import logging
LOG = logging.getLogger('.' + __name__)
LOG.progagate = True
from ..const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
@ -252,7 +255,12 @@ class BasePluginManager(object):
if pdata.fpath not in sys.path:
if pdata.mod_name:
sys.path.insert(0, pdata.fpath)
module = __import__(pdata.mod_name)
try:
module = __import__(pdata.mod_name)
except ValueError as err:
LOG.warning('Plugin error: %s', err)
except ImportError as err:
LOG.warning('Plugin error: %s', err)
sys.path.pop(0)
else:
print("WARNING: module cannot be loaded")