Better errors when browsing spineless books

This commit is contained in:
Kovid Goyal 2021-03-26 16:42:13 +05:30
parent 39b894f1fe
commit e895b4ebde
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 13 additions and 0 deletions

View File

@ -59,6 +59,10 @@ RENDER_VERSION = 1
BLANK_JPEG = b'\xff\xd8\xff\xdb\x00C\x00\x03\x02\x02\x02\x02\x02\x03\x02\x02\x02\x03\x03\x03\x03\x04\x06\x04\x04\x04\x04\x04\x08\x06\x06\x05\x06\t\x08\n\n\t\x08\t\t\n\x0c\x0f\x0c\n\x0b\x0e\x0b\t\t\r\x11\r\x0e\x0f\x10\x10\x11\x10\n\x0c\x12\x13\x12\x10\x13\x0f\x10\x10\x10\xff\xc9\x00\x0b\x08\x00\x01\x00\x01\x01\x01\x11\x00\xff\xcc\x00\x06\x00\x10\x10\x05\xff\xda\x00\x08\x01\x01\x00\x00?\x00\xd2\xcf \xff\xd9' # noqa BLANK_JPEG = b'\xff\xd8\xff\xdb\x00C\x00\x03\x02\x02\x02\x02\x02\x03\x02\x02\x02\x03\x03\x03\x03\x04\x06\x04\x04\x04\x04\x04\x08\x06\x06\x05\x06\t\x08\n\n\t\x08\t\t\n\x0c\x0f\x0c\n\x0b\x0e\x0b\t\t\r\x11\r\x0e\x0f\x10\x10\x11\x10\n\x0c\x12\x13\x12\x10\x13\x0f\x10\x10\x10\xff\xc9\x00\x0b\x08\x00\x01\x00\x01\x01\x01\x11\x00\xff\xcc\x00\x06\x00\x10\x10\x05\xff\xda\x00\x08\x01\x01\x00\x00?\x00\xd2\xcf \xff\xd9' # noqa
class Spineless(ValueError):
pass
def XPath(expr): def XPath(expr):
ans = XPath.cache.get(expr) ans = XPath.cache.get(expr)
if ans is None: if ans is None:
@ -841,6 +845,12 @@ def render(pathtoebook, output_dir, book_hash=None, serialize_metadata=False, ex
book_hash=book_hash, save_bookmark_data=extract_annotations, book_hash=book_hash, save_bookmark_data=extract_annotations,
book_metadata=mi, virtualize_resources=virtualize_resources book_metadata=mi, virtualize_resources=virtualize_resources
) )
try:
has_spine = next(container.spine_names)
except StopIteration:
has_spine = False
if not has_spine:
raise Spineless('Book is empty, no content in spine')
if serialize_metadata: if serialize_metadata:
from calibre.ebooks.metadata.book.serialize import metadata_as_dict from calibre.ebooks.metadata.book.serialize import metadata_as_dict
d = metadata_as_dict(mi) d = metadata_as_dict(mi)

View File

@ -927,6 +927,9 @@ class View:
if ui_operations.update_last_read_time: if ui_operations.update_last_read_time:
ui_operations.update_last_read_time(book) ui_operations.update_last_read_time(book)
pos = {'replace_history':True} pos = {'replace_history':True}
if not book.manifest.spine.length:
ui_operations.show_error(_('Invalid book'), _('This book is empty, with no items in the spine'))
return
name = book.manifest.spine[0] name = book.manifest.spine[0]
cfi = None cfi = None
if initial_position and initial_position.type is 'cfi' and initial_position.data.startswith('epubcfi(/'): if initial_position and initial_position.type is 'cfi' and initial_position.data.startswith('epubcfi(/'):