From 592c00d55c0aed3cca70fd5d62d95f376db7cefd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 12 Nov 2015 11:22:29 +0530 Subject: [PATCH] Report unhandled exceptions to user --- src/pyj/book_list/boss.pyj | 10 ++++++++++ src/pyj/modals.pyj | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/pyj/book_list/boss.pyj b/src/pyj/book_list/boss.pyj index 6b69120a7c..a82b327f02 100644 --- a/src/pyj/book_list/boss.pyj +++ b/src/pyj/book_list/boss.pyj @@ -2,6 +2,8 @@ # License: GPL v3 Copyright: 2015, Kovid Goyal from book_list.ui import UI +from modals import error_dialog +from gettext import gettext as _ class Boss: @@ -11,7 +13,15 @@ class Boss: self.current_library_name = interface_data['library_map'][self.current_library_id] self.update_window_title() self.ui = UI(interface_data) + window.onerror = bind(self.onerror, self) def update_window_title(self): 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 + '
' + str.format('Error at {}:{}:{}', fname, line_number, column_number or '') + '' + details = '' + if error_object and error_object.stack: + details = error_object.stack + error_dialog(_('Unhandled error'), msg, details) diff --git a/src/pyj/modals.pyj b/src/pyj/modals.pyj index d9820f26bd..fd3b5641c4 100644 --- a/src/pyj/modals.pyj +++ b/src/pyj/modals.pyj @@ -101,6 +101,10 @@ def create_simple_dialog(title, msg, details, icon_name, prefix): show_details.style.display = 'none' 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( E.div( 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, 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'), show_details, E.div(details,