Fix error reporting in the new viewer

This commit is contained in:
Kovid Goyal 2018-09-24 13:35:51 +05:30
parent 783ff58129
commit d62024d1b1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 20 additions and 19 deletions

View File

@ -141,7 +141,13 @@ class WebPage(QWebEnginePage):
self.bridge = ViewerBridge(self)
def javaScriptConsoleMessage(self, level, msg, linenumber, source_id):
prints('%s:%s: %s' % (source_id, linenumber, msg))
if level >= QWebEnginePage.ErrorMessageLevel and source_id == 'userscript:viewer.js':
error_dialog(self.parent(), _('Unhandled error'), _(
'There was an unhandled error: {} at line: {} of {}').format(
msg, linenumber, source_id.partition(':')[2]), show=True)
prefix = {QWebEnginePage.InfoMessageLevel: 'INFO', QWebEnginePage.WarningMessageLevel: 'WARNING'}.get(
level, 'ERROR')
prints('%s: %s:%s: %s' % (prefix, source_id, linenumber, msg))
def acceptNavigationRequest(self, url, req_type, is_main_frame):
if req_type == self.NavigationTypeReload:

View File

@ -9,7 +9,7 @@ from gettext import gettext as _
import initialize # noqa: unused-import
from ajax import ajax
from book_list.globals import set_session_data
from modals import error_dialog
from modals import error_dialog, create_modal_container
from qt import from_python, to_python
from read_book.db import new_book
from read_book.globals import runtime, ui_operations
@ -45,12 +45,13 @@ def manifest_received(key, end_type, xhr, ev):
nonlocal book
if end_type is 'load':
book = new_book(key, {})
book.manifest = xhr.response
book.manifest = JSON.parse(xhr.responseText)
book.metadata = book.manifest.metadata
book.stored_files = {}
book.is_complete = True
v'delete book.manifest["metadata"]'
v'delete book.manifest["last_read_positions"]'
view.display_book(book)
else:
error_dialog(_('Could not open book'), _(
'Failed to load book manifest, click "Show details" for more info'),
@ -99,23 +100,16 @@ def start_book_load(key, prefs):
def onerror(msg, script_url, line_number, column_number, error_object):
if error_object is None:
# This happens for cross-domain errors (probably javascript injected
# into the browser via extensions/ userscripts and the like). It also
# happens all the time when using Chrom on Safari, so ignore this
# type of error
console.log(f'Unhandled error from external javascript, ignoring: {msg} {script_url} {line_number}')
return
if not error_object:
# cross domain error
return False
fname = script_url.rpartition('/')[-1] or script_url
msg += '<br><span style="font-size:smaller">' + 'Error at {}:{}:{}'.format(fname, line_number, column_number or '') + '</span>'
details = ''
console.log(error_object)
try:
fname = script_url.rpartition('/')[-1] or script_url
msg = msg + '<br><span style="font-size:smaller">' + 'Error at {}:{}:{}'.format(fname, line_number, column_number or '') + '</span>'
details = ''
details = traceback.format_exception(error_object).join('')
error_dialog(_('Unhandled error'), msg, details)
return True
except:
console.log('There was an error in the unhandled exception handler')
details = traceback.format_exception(error_object).join('')
error_dialog(_('Unhandled error'), msg, details)
return True
if window is window.top:
@ -126,6 +120,7 @@ if window is window.top:
ui_operations.show_error = show_error
document.body.appendChild(E.div(id='view'))
window.onerror = onerror
create_modal_container()
else:
# iframe
pass