Fix printing of tracebacks broken when third party plugins with non-UTF-8 source code present

This commit is contained in:
Kovid Goyal
2020-11-04 08:37:15 +05:30
parent 37fee2b5b2
commit 6ba70b06aa
+5 -1
View File
@@ -164,7 +164,11 @@ class CalibrePluginLoader:
return src
def get_source(self, fullname=None):
return self.get_source_as_bytes(fullname).decode('utf-8-sig').replace('\r\n', '\n')
raw = self.get_source_as_bytes(fullname)
try:
return raw.decode('utf-8-sig', 'replace').replace('\r\n', '\n')
except Exception:
return ''
def get_filename(self, fullname):
return self.filename