mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Improve error reporting
This commit is contained in:
parent
facc4045d4
commit
efb2d424a7
@ -120,9 +120,19 @@ def prepare_convert(temp_path, key, st):
|
||||
}
|
||||
|
||||
|
||||
class ConversionFailure(ValueError):
|
||||
|
||||
def __init__(self, book_path, worker_output):
|
||||
self.book_path = book_path
|
||||
self.worker_output = worker_output
|
||||
ValueError.__init__(
|
||||
self, 'Failed to convert book: {} with error:\n{}'.format(book_path, worker_output))
|
||||
|
||||
|
||||
def do_convert(path, temp_path, key, instance):
|
||||
tdir = os.path.join(temp_path, instance['path'])
|
||||
with TemporaryFile('log.txt') as logpath, open(logpath, 'w+b') as logf:
|
||||
with TemporaryFile('log.txt') as logpath:
|
||||
with open(logpath, 'w+b') as logf:
|
||||
p = start_pipe_worker('from calibre.srv.render_book import viewer_main; viewer_main()', stdout=logf, stderr=logf)
|
||||
p.stdin.write(msgpack_dumps((
|
||||
path, tdir, {'size': instance['file_size'], 'mtime': instance['file_mtime'], 'hash': key},
|
||||
@ -130,8 +140,8 @@ def do_convert(path, temp_path, key, instance):
|
||||
p.stdin.close()
|
||||
if p.wait() != 0:
|
||||
with lopen(logpath, 'rb') as logf:
|
||||
raise Exception('Failed to convert book: {} with errors:\n{}'.format(
|
||||
path, logf.read().decode('utf-8', 'replace')))
|
||||
worker_output = logf.read().decode('utf-8', 'replace')
|
||||
raise ConversionFailure(path, worker_output)
|
||||
size = 0
|
||||
for f in walk(tdir):
|
||||
size += os.path.getsize(f)
|
||||
|
@ -6,6 +6,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from collections import defaultdict, namedtuple
|
||||
from hashlib import sha256
|
||||
@ -333,14 +334,15 @@ class EbookViewer(MainWindow):
|
||||
open_at, self.pending_open_at = self.pending_open_at, None
|
||||
if not ok:
|
||||
self.setWindowTitle(self.base_window_title)
|
||||
tb = data['tb']
|
||||
tb = data['tb'].strip()
|
||||
tb = re.split(r'^calibre\.gui2\.viewer\.convert_book\.ConversionFailure:\s*', tb, maxsplit=1, flags=re.M)[-1]
|
||||
last_line = tuple(tb.strip().splitlines())[-1]
|
||||
if last_line.startswith('calibre.ebooks.DRMError'):
|
||||
DRMErrorMessage(self).exec_()
|
||||
else:
|
||||
error_dialog(self, _('Loading book failed'), _(
|
||||
'Failed to open the book at {0}. Click "Show details" for more info.').format(data['pathtoebook']),
|
||||
det_msg=data['tb'], show=True)
|
||||
det_msg=tb, show=True)
|
||||
self.loading_overlay.hide()
|
||||
self.web_view.show_home_page()
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user