mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add an unhandled exception handler for the iframe
This commit is contained in:
parent
804fca17e2
commit
f8ae941269
@ -4,7 +4,7 @@ from __python__ import bound_methods, hash_literals
|
|||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
from aes import GCM
|
from aes import GCM
|
||||||
from gettext import install
|
from gettext import install, gettext as _
|
||||||
from read_book.globals import set_boss, set_current_spine_item, current_layout_mode, current_spine_item, set_layout_mode
|
from read_book.globals import set_boss, set_current_spine_item, current_layout_mode, current_spine_item, set_layout_mode
|
||||||
from read_book.resources import finalize_resources, unserialize_html
|
from read_book.resources import finalize_resources, unserialize_html
|
||||||
from read_book.flow_mode import flow_to_scroll_fraction, flow_onwheel, flow_onkeydown, layout as flow_layout
|
from read_book.flow_mode import flow_to_scroll_fraction, flow_onwheel, flow_onkeydown, layout as flow_layout
|
||||||
@ -50,7 +50,7 @@ class Boss:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.log('Error in iframe message handler:')
|
console.log('Error in iframe message handler:')
|
||||||
console.log(e)
|
console.log(e)
|
||||||
self.send_message('error', details=traceback.format_exc(), msg=e.toString())
|
self.send_message('error', title=_('Error in message handler'), details=traceback.format_exc(), msg=e.toString())
|
||||||
else:
|
else:
|
||||||
print('Unknown action in message to iframe from parent: ' + data.action)
|
print('Unknown action in message to iframe from parent: ' + data.action)
|
||||||
|
|
||||||
@ -58,6 +58,18 @@ class Boss:
|
|||||||
self.gcm_from_parent, self.gcm_to_parent = GCM(data.secret.subarray(0, 32)), GCM(data.secret.subarray(32))
|
self.gcm_from_parent, self.gcm_to_parent = GCM(data.secret.subarray(0, 32)), GCM(data.secret.subarray(32))
|
||||||
if data.translations:
|
if data.translations:
|
||||||
install(data.translations)
|
install(data.translations)
|
||||||
|
window.onerror = self.onerror
|
||||||
|
|
||||||
|
def onerror(self, msg, script_url, line_number, column_number, error_object):
|
||||||
|
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 = traceback.format_exception(error_object).join('') if error_object else ''
|
||||||
|
self.send_message('error', title=_('Unhandled error'), details=details, msg=msg)
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
console.log('There was an error in the iframe unhandled exception handler')
|
||||||
|
|
||||||
def display(self, data):
|
def display(self, data):
|
||||||
self.encrypted_communications = True
|
self.encrypted_communications = True
|
||||||
@ -127,6 +139,7 @@ class Boss:
|
|||||||
try:
|
try:
|
||||||
data = JSON.parse(evt.currentTarget.getAttribute(link_attr))
|
data = JSON.parse(evt.currentTarget.getAttribute(link_attr))
|
||||||
except:
|
except:
|
||||||
|
print('WARNING: Failed to parse link data {}, ignoring'.format(evt.currentTarget.getAttribute(link_attr)))
|
||||||
return
|
return
|
||||||
name, frag = data.name, data.frag
|
name, frag = data.name, data.frag
|
||||||
if name is current_spine_item().name:
|
if name is current_spine_item().name:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user