Handle not being able to decode plugin loading failure exceptions

This commit is contained in:
Kovid Goyal 2019-11-23 07:52:18 +05:30
parent 55e8d547af
commit 86f972cde1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -2,7 +2,7 @@
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
from __future__ import print_function, unicode_literals
from polyglot.builtins import map, unicode_type, environ_item, hasenv, getenv
from polyglot.builtins import map, unicode_type, environ_item, hasenv, getenv, as_unicode, native_string_type
import sys, locale, codecs, os, importlib, collections
__appname__ = 'calibre'
@ -213,7 +213,10 @@ class Plugins(collections.Mapping):
p = importlib.import_module(name)
except Exception as err:
p = None
try:
plugin_err = unicode_type(err)
except Exception:
plugin_err = as_unicode(native_string_type(err), encoding=preferred_encoding, errors='replace')
self._plugins[name] = p, plugin_err
sys.path.remove(plugins_loc)