mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Fix error reporting in the new viewer
This commit is contained in:
parent
783ff58129
commit
d62024d1b1
@ -141,7 +141,13 @@ class WebPage(QWebEnginePage):
|
|||||||
self.bridge = ViewerBridge(self)
|
self.bridge = ViewerBridge(self)
|
||||||
|
|
||||||
def javaScriptConsoleMessage(self, level, msg, linenumber, source_id):
|
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):
|
def acceptNavigationRequest(self, url, req_type, is_main_frame):
|
||||||
if req_type == self.NavigationTypeReload:
|
if req_type == self.NavigationTypeReload:
|
||||||
|
@ -9,7 +9,7 @@ from gettext import gettext as _
|
|||||||
import initialize # noqa: unused-import
|
import initialize # noqa: unused-import
|
||||||
from ajax import ajax
|
from ajax import ajax
|
||||||
from book_list.globals import set_session_data
|
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 qt import from_python, to_python
|
||||||
from read_book.db import new_book
|
from read_book.db import new_book
|
||||||
from read_book.globals import runtime, ui_operations
|
from read_book.globals import runtime, ui_operations
|
||||||
@ -45,12 +45,13 @@ def manifest_received(key, end_type, xhr, ev):
|
|||||||
nonlocal book
|
nonlocal book
|
||||||
if end_type is 'load':
|
if end_type is 'load':
|
||||||
book = new_book(key, {})
|
book = new_book(key, {})
|
||||||
book.manifest = xhr.response
|
book.manifest = JSON.parse(xhr.responseText)
|
||||||
book.metadata = book.manifest.metadata
|
book.metadata = book.manifest.metadata
|
||||||
book.stored_files = {}
|
book.stored_files = {}
|
||||||
book.is_complete = True
|
book.is_complete = True
|
||||||
v'delete book.manifest["metadata"]'
|
v'delete book.manifest["metadata"]'
|
||||||
v'delete book.manifest["last_read_positions"]'
|
v'delete book.manifest["last_read_positions"]'
|
||||||
|
view.display_book(book)
|
||||||
else:
|
else:
|
||||||
error_dialog(_('Could not open book'), _(
|
error_dialog(_('Could not open book'), _(
|
||||||
'Failed to load book manifest, click "Show details" for more info'),
|
'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):
|
def onerror(msg, script_url, line_number, column_number, error_object):
|
||||||
if error_object is None:
|
if not error_object:
|
||||||
# This happens for cross-domain errors (probably javascript injected
|
# cross domain error
|
||||||
# into the browser via extensions/ userscripts and the like). It also
|
return False
|
||||||
# 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
|
|
||||||
console.log(error_object)
|
|
||||||
try:
|
|
||||||
fname = script_url.rpartition('/')[-1] or script_url
|
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>'
|
msg += '<br><span style="font-size:smaller">' + 'Error at {}:{}:{}'.format(fname, line_number, column_number or '') + '</span>'
|
||||||
details = ''
|
details = ''
|
||||||
|
console.log(error_object)
|
||||||
details = traceback.format_exception(error_object).join('')
|
details = traceback.format_exception(error_object).join('')
|
||||||
error_dialog(_('Unhandled error'), msg, details)
|
error_dialog(_('Unhandled error'), msg, details)
|
||||||
return True
|
return True
|
||||||
except:
|
|
||||||
console.log('There was an error in the unhandled exception handler')
|
|
||||||
|
|
||||||
|
|
||||||
if window is window.top:
|
if window is window.top:
|
||||||
@ -126,6 +120,7 @@ if window is window.top:
|
|||||||
ui_operations.show_error = show_error
|
ui_operations.show_error = show_error
|
||||||
document.body.appendChild(E.div(id='view'))
|
document.body.appendChild(E.div(id='view'))
|
||||||
window.onerror = onerror
|
window.onerror = onerror
|
||||||
|
create_modal_container()
|
||||||
else:
|
else:
|
||||||
# iframe
|
# iframe
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user