From b388a91180a7a59275ec62f59408ffcc0b417bd3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 31 Dec 2024 09:10:40 +0530 Subject: [PATCH] Better error message when ToC editor is opened to an non-HTML file --- src/calibre/gui2/toc/location.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/gui2/toc/location.py b/src/calibre/gui2/toc/location.py index 313ff1b5c0..a9d3725da3 100644 --- a/src/calibre/gui2/toc/location.py +++ b/src/calibre/gui2/toc/location.py @@ -397,6 +397,8 @@ class ItemEdit(QWidget): name = self.current_name = str(item.data(Qt.ItemDataRole.DisplayRole) or '') # Ensure encoding map is populated root = self.container.parsed(name) + if not hasattr(root, 'xpath'): + return error_dialog(self, _('Not an HTML file'), _('The file {} is not marked as an HTML file in the OPF and cannot be displayed').format(name)) nasty = root.xpath('//*[local-name()="head"]/*[local-name()="p"]') if nasty: body = root.xpath('//*[local-name()="body"]')