From bcabbd88d10ebe4cbf1d19e347b86a120137a4cc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 13 Oct 2016 21:55:21 +0530 Subject: [PATCH] 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) --- src/calibre/gui2/tweak_book/boss.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index 41d850d194..c82292b588 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -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]))