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,18 +120,28 @@ 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):
|
def do_convert(path, temp_path, key, instance):
|
||||||
tdir = os.path.join(temp_path, instance['path'])
|
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:
|
||||||
p = start_pipe_worker('from calibre.srv.render_book import viewer_main; viewer_main()', stdout=logf, stderr=logf)
|
with open(logpath, 'w+b') as logf:
|
||||||
p.stdin.write(msgpack_dumps((
|
p = start_pipe_worker('from calibre.srv.render_book import viewer_main; viewer_main()', stdout=logf, stderr=logf)
|
||||||
path, tdir, {'size': instance['file_size'], 'mtime': instance['file_mtime'], 'hash': key},
|
p.stdin.write(msgpack_dumps((
|
||||||
)))
|
path, tdir, {'size': instance['file_size'], 'mtime': instance['file_mtime'], 'hash': key},
|
||||||
p.stdin.close()
|
)))
|
||||||
if p.wait() != 0:
|
p.stdin.close()
|
||||||
with lopen(logpath, 'rb') as logf:
|
if p.wait() != 0:
|
||||||
raise Exception('Failed to convert book: {} with errors:\n{}'.format(
|
with lopen(logpath, 'rb') as logf:
|
||||||
path, logf.read().decode('utf-8', 'replace')))
|
worker_output = logf.read().decode('utf-8', 'replace')
|
||||||
|
raise ConversionFailure(path, worker_output)
|
||||||
size = 0
|
size = 0
|
||||||
for f in walk(tdir):
|
for f in walk(tdir):
|
||||||
size += os.path.getsize(f)
|
size += os.path.getsize(f)
|
||||||
|
@ -6,6 +6,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
from collections import defaultdict, namedtuple
|
from collections import defaultdict, namedtuple
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
@ -333,14 +334,15 @@ class EbookViewer(MainWindow):
|
|||||||
open_at, self.pending_open_at = self.pending_open_at, None
|
open_at, self.pending_open_at = self.pending_open_at, None
|
||||||
if not ok:
|
if not ok:
|
||||||
self.setWindowTitle(self.base_window_title)
|
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]
|
last_line = tuple(tb.strip().splitlines())[-1]
|
||||||
if last_line.startswith('calibre.ebooks.DRMError'):
|
if last_line.startswith('calibre.ebooks.DRMError'):
|
||||||
DRMErrorMessage(self).exec_()
|
DRMErrorMessage(self).exec_()
|
||||||
else:
|
else:
|
||||||
error_dialog(self, _('Loading book failed'), _(
|
error_dialog(self, _('Loading book failed'), _(
|
||||||
'Failed to open the book at {0}. Click "Show details" for more info.').format(data['pathtoebook']),
|
'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.loading_overlay.hide()
|
||||||
self.web_view.show_home_page()
|
self.web_view.show_home_page()
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user