mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Report unhandled exceptions to user
This commit is contained in:
parent
16c216e8ac
commit
592c00d55c
@ -2,6 +2,8 @@
|
|||||||
# License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
from book_list.ui import UI
|
from book_list.ui import UI
|
||||||
|
from modals import error_dialog
|
||||||
|
from gettext import gettext as _
|
||||||
|
|
||||||
class Boss:
|
class Boss:
|
||||||
|
|
||||||
@ -11,7 +13,15 @@ class Boss:
|
|||||||
self.current_library_name = interface_data['library_map'][self.current_library_id]
|
self.current_library_name = interface_data['library_map'][self.current_library_id]
|
||||||
self.update_window_title()
|
self.update_window_title()
|
||||||
self.ui = UI(interface_data)
|
self.ui = UI(interface_data)
|
||||||
|
window.onerror = bind(self.onerror, self)
|
||||||
|
|
||||||
def update_window_title(self):
|
def update_window_title(self):
|
||||||
document.title = 'calibre :: ' + self.current_library_name
|
document.title = 'calibre :: ' + self.current_library_name
|
||||||
|
|
||||||
|
def onerror(self, msg, script_url, line_number, column_number, error_object):
|
||||||
|
fname = str.rpartition(script_url, '/')[-1] or script_url
|
||||||
|
msg = msg + '<br><span style="font-size:smaller">' + str.format('Error at {}:{}:{}', fname, line_number, column_number or '') + '</span>'
|
||||||
|
details = ''
|
||||||
|
if error_object and error_object.stack:
|
||||||
|
details = error_object.stack
|
||||||
|
error_dialog(_('Unhandled error'), msg, details)
|
||||||
|
@ -101,6 +101,10 @@ def create_simple_dialog(title, msg, details, icon_name, prefix):
|
|||||||
show_details.style.display = 'none'
|
show_details.style.display = 'none'
|
||||||
show_details.nextSibling.style.display = 'block'
|
show_details.nextSibling.style.display = 'block'
|
||||||
)
|
)
|
||||||
|
is_html_msg = /<[a-zA-Z]/.test(msg)
|
||||||
|
html_container = E.div()
|
||||||
|
if is_html_msg:
|
||||||
|
html_container.innerHTML = msg
|
||||||
parent.appendChild(
|
parent.appendChild(
|
||||||
E.div(
|
E.div(
|
||||||
style='max-width:60em; text-align: left',
|
style='max-width:60em; text-align: left',
|
||||||
@ -108,7 +112,7 @@ def create_simple_dialog(title, msg, details, icon_name, prefix):
|
|||||||
E.i(class_='fa fa-lg fa-' + icon_name, style='color:red'), E.span('\xa0' + prefix + '\xa0', style='font-variant:small-caps'), title,
|
E.i(class_='fa fa-lg fa-' + icon_name, style='color:red'), E.span('\xa0' + prefix + '\xa0', style='font-variant:small-caps'), title,
|
||||||
style='font-weight: bold; font-size: ' + get_font_size('title')
|
style='font-weight: bold; font-size: ' + get_font_size('title')
|
||||||
),
|
),
|
||||||
E.div(msg, style='padding-top: 1em; margin-top: 1em; border-top: 1px solid currentColor'),
|
E.div((html_container if is_html_msg else msg), style='padding-top: 1em; margin-top: 1em; border-top: 1px solid currentColor'),
|
||||||
E.div(style='display: ' + ('block' if details else 'none'),
|
E.div(style='display: ' + ('block' if details else 'none'),
|
||||||
show_details,
|
show_details,
|
||||||
E.div(details,
|
E.div(details,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user