Edit Book: Better error message when user tries to open a Check Book item that refers to a file that has beed deleted since the last time Check Book was run. Fixes #1632897 [KeyError after deleting unreferenced file](https://bugs.launchpad.net/calibre/+bug/1632897)

This commit is contained in:
Kovid Goyal 2016-10-13 21:55:21 +05:30
parent 51024a7d9d
commit bcabbd88d1

View File

@ -1197,11 +1197,16 @@ class Boss(QObject):
def check_item_activated(self, item):
is_mult = item.has_multiple_locations and getattr(item, 'current_location_index', None) is not None
name = item.all_locations[item.current_location_index][0] if is_mult else item.name
editor = None
if name in editors:
editor = editors[name]
self.gui.central.show_editor(editor)
else:
editor = self.edit_file_requested(name, None, current_container().mime_map[name])
try:
editor = self.edit_file_requested(name, None, current_container().mime_map[name])
except KeyError:
error_dialog(self.gui, _('File deleted'), _(
'The file {} has already been deleted, re-run Check Book to update the results.').format(name), show=True)
if getattr(editor, 'has_line_numbers', False):
if is_mult:
editor.go_to_line(*(item.all_locations[item.current_location_index][1:3]))