diff --git a/src/pyj/book_list/book_details.pyj b/src/pyj/book_list/book_details.pyj index c8f831a275..42812806ed 100644 --- a/src/pyj/book_list/book_details.pyj +++ b/src/pyj/book_list/book_details.pyj @@ -1,6 +1,7 @@ # vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal +import traceback from ajax import ajax from book_list.globals import get_current_query from book_list.theme import get_font_size @@ -241,10 +242,9 @@ def render_metadata(mi, interface_data, table, field_list=None): continue try: process_field(field, fm) - except Exception as err: + except Exception: print('Failed to render metadata field: ' + field) - print(err.toString()) - print(err.stack) + traceback.print_exc() for i, field in enumerate(sorted(comments)): comment = comments[field] diff --git a/src/pyj/book_list/boss.pyj b/src/pyj/book_list/boss.pyj index bd1661e51d..7f5f461e0d 100644 --- a/src/pyj/book_list/boss.pyj +++ b/src/pyj/book_list/boss.pyj @@ -1,6 +1,7 @@ # vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2015, Kovid Goyal +import traceback from ajax import encode_query from dom import set_css from elementmaker import E @@ -76,8 +77,8 @@ class Boss: fname = script_url.rpartition('/')[-1] or script_url msg = msg + '
' + 'Error at {}:{}:{}'.format(fname, line_number, column_number or '') + '' details = '' - if error_object and error_object.stack: - details = error_object.stack + if error_object: + details = traceback.format_exception(error_object).join('') error_dialog(_('Unhandled error'), msg, details) return True except: diff --git a/src/pyj/book_list/ui.pyj b/src/pyj/book_list/ui.pyj index 37b8b738ce..1a0cf74df8 100644 --- a/src/pyj/book_list/ui.pyj +++ b/src/pyj/book_list/ui.pyj @@ -1,6 +1,7 @@ # vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2015, Kovid Goyal +import traceback from book_list.globals import get_boss, get_session_data from book_list.search import SearchPanel from book_list.top_bar import TopBar @@ -196,7 +197,7 @@ class UI: data = JSON.parse(xhr.responseText) boss.change_books(data) except Exception as err: - return error_dialog(_('Could not change library'), err + '', details=err.stack) + return error_dialog(_('Could not change library'), err + '', details=traceback.format_exc()) self.show_panel(self.ROOT_PANEL) window.scrollTo(0, 0) elif end_type is not 'abort': diff --git a/src/pyj/book_list/views.pyj b/src/pyj/book_list/views.pyj index ef5978499a..ea99ac247e 100644 --- a/src/pyj/book_list/views.pyj +++ b/src/pyj/book_list/views.pyj @@ -1,6 +1,7 @@ # vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2015, Kovid Goyal +import traceback from ajax import ajax_send from dom import set_css, build_rule, clear from elementmaker import E @@ -145,8 +146,8 @@ class BooksView: raise Exception('No books ids object in search result from server') self.render_ids(data.search_result.book_ids) self.interface_data.search_result = data.search_result - except Exception as err: - error_dialog(_('Could not get more books'), _('Server returned an invalid response'), err.stack or err.toString()) + except Exception: + error_dialog(_('Could not get more books'), _('Server returned an invalid response'), traceback.format_exc()) elif end_type is not 'abort': error_dialog(_('Could not get more books'), xhr.error_html) @@ -230,7 +231,7 @@ class BooksView: data = JSON.parse(xhr.responseText) boss.change_books(data) except Exception as err: - return error_dialog(_('Could not change sort order'), err + '', details=err.stack) + return error_dialog(_('Could not change sort order'), err + '', details=traceback.format_exc()) boss.ui.show_panel(boss.ui.ROOT_PANEL) window.scrollTo(0, 0) elif end_type is not 'abort': @@ -251,7 +252,7 @@ class BooksView: data = JSON.parse(xhr.responseText) boss.change_books(data) except Exception as err: - return error_dialog(_('Could not change search query'), err + '', details=err.stack) + return error_dialog(_('Could not change search query'), err + '', details=traceback.format_exc()) self.update_fetching_status() ed = xhr.extra_data_for_callback boss.ui.show_panel(ed.panel_to_show or boss.ui.ROOT_PANEL, push_state=ed.push_state) diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index c28a809bcb..4536daa8a3 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -2,6 +2,7 @@ # License: GPL v3 Copyright: 2016, Kovid Goyal from __python__ import bound_methods +import traceback from aes import GCM from gettext import install from read_book.globals import set_boss, set_current_spine_item, current_layout_mode, current_spine_item @@ -45,7 +46,7 @@ class Boss: except Exception as e: console.log('Error in iframe message handler:') console.log(e) - self.send_message('error', details=e.stack, msg=e.toString()) + self.send_message('error', details=traceback.format_exc(), msg=e.toString()) else: print('Unknown action in message to iframe from parent: ' + data.action) diff --git a/src/pyj/read_book/ui.pyj b/src/pyj/read_book/ui.pyj index e5e6191cb3..6c0da23cfd 100644 --- a/src/pyj/read_book/ui.pyj +++ b/src/pyj/read_book/ui.pyj @@ -2,6 +2,7 @@ # License: GPL v3 Copyright: 2016, Kovid Goyal # globals: __RENDER_VERSION__ +import traceback from ajax import ajax, encode_query from elementmaker import E from gettext import gettext as _ @@ -138,10 +139,10 @@ class ReadUI: xhr.error_html) try: manifest = JSON.parse(xhr.responseText) - except Exception as err: + except Exception: return self.show_error(_('Failed to load book manifest'), _('The manifest for {title} is not valid').format(title=self.current_metadata.title), - err.stack or err.toString()) + traceback.format_exc()) if manifest.version is not RENDER_VERSION: return self.show_error(_('calibre upgraded!'), _( 'A newer version of calibre is available, please click the reload button in your browser.'))