mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Handle errors in the worker
This commit is contained in:
parent
a365ac1862
commit
9f1d9a9781
@ -8,9 +8,12 @@ from book_list.theme import get_color
|
||||
from complete import create_search_bar
|
||||
from dom import add_extra_css, build_rule, svgicon
|
||||
from gettext import gettext as _
|
||||
from modals import error_dialog
|
||||
from read_book.globals import ui_operations
|
||||
from read_book.search_worker import worker_main
|
||||
from read_book.resources import text_from_serialized_html
|
||||
from read_book.search_worker import (
|
||||
CONNECT_FAILED, DB_ERROR, GET_SPINE_FAILED, UNHANDLED_ERROR, worker_main
|
||||
)
|
||||
from read_book.shortcuts import shortcut_for_key_event
|
||||
from worker import start_worker
|
||||
|
||||
@ -67,10 +70,23 @@ class SearchOverlay:
|
||||
def on_worker_message(self, evt):
|
||||
msg = evt.data
|
||||
if msg.type is 'error':
|
||||
pass
|
||||
details = msg.msg
|
||||
emsg = _('Unknown error')
|
||||
if msg.code is GET_SPINE_FAILED:
|
||||
emsg = _('Loading text from the book failed.')
|
||||
elif msg.code is CONNECT_FAILED:
|
||||
emsg = _('Connecting to database storing the local copy of the book failed in the worker thread.')
|
||||
elif msg.code is UNHANDLED_ERROR:
|
||||
emsg = _('There was an unhandled error while searching.')
|
||||
elif msg.code is DB_ERROR:
|
||||
emsg = msg.error.msg
|
||||
details = msg.error.details
|
||||
error_dialog(_('Could not search'), emsg, details)
|
||||
elif msg.id is self.search_in_flight_id:
|
||||
if msg.type is 'search_complete':
|
||||
self.search_in_flight_id = None
|
||||
elif msg.type is 'search_result':
|
||||
pass
|
||||
|
||||
def clear_caches(self):
|
||||
if self._worker:
|
||||
|
@ -4,6 +4,7 @@ from __python__ import bound_methods, hash_literals
|
||||
|
||||
from read_book.db import DB
|
||||
from read_book.resources import text_from_serialized_html
|
||||
from traceback import format_exception
|
||||
|
||||
GET_SPINE_FAILED = 1
|
||||
CONNECT_FAILED = 2
|
||||
@ -200,5 +201,6 @@ def worker_main():
|
||||
elif e.data.type is 'clear_caches':
|
||||
wc.clear_caches()
|
||||
|
||||
self.onerror = def(e):
|
||||
send_error(UNHANDLED_ERROR, f'{e.line}:{e.message}')
|
||||
self.addEventListener('error', def (e):
|
||||
send_error(UNHANDLED_ERROR, f'{e.lineno}:{e.message}' + '\n\n' + format_exception(e.error).join(''))
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user