Get proper unicode printouts from the unhandled exception handler

This commit is contained in:
Kovid Goyal 2019-12-12 22:48:10 +05:30
parent e7e78da5c1
commit 1b1d51b078
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -10,8 +10,8 @@ from PyQt5.Qt import (QMainWindow, QTimer, QAction, QMenu, QMenuBar, QIcon,
QObject) QObject)
from calibre.utils.config import OptionParser from calibre.utils.config import OptionParser
from calibre.gui2 import error_dialog from calibre.gui2 import error_dialog
from calibre import prints, force_unicode, as_unicode from calibre import prints, as_unicode
from polyglot.io import PolyglotBytesIO from polyglot.io import PolyglotStringIO
def option_parser(usage='''\ def option_parser(usage='''\
@ -134,7 +134,7 @@ class MainWindow(QMainWindow):
return return
import traceback import traceback
try: try:
sio = PolyglotBytesIO(errors='replace') sio = PolyglotStringIO(errors='replace')
try: try:
from calibre.debug import print_basic_debug_info from calibre.debug import print_basic_debug_info
print_basic_debug_info(out=sio) print_basic_debug_info(out=sio)
@ -144,11 +144,10 @@ class MainWindow(QMainWindow):
if getattr(value, 'locking_debug_msg', None): if getattr(value, 'locking_debug_msg', None):
prints(value.locking_debug_msg, file=sio) prints(value.locking_debug_msg, file=sio)
fe = sio.getvalue() fe = sio.getvalue()
prints(fe, file=sys.stderr)
fe = force_unicode(fe)
msg = '<b>%s</b>:'%exc_type.__name__ + as_unicode(value) msg = '<b>%s</b>:'%exc_type.__name__ + as_unicode(value)
error_dialog(self, _('Unhandled exception'), msg, det_msg=fe, error_dialog(self, _('Unhandled exception'), msg, det_msg=fe,
show=True) show=True)
prints(fe, file=sys.stderr)
except BaseException: except BaseException:
pass pass
except: except: