From bdb6839a76bf4a7faa6f987a63e33189e3024c8f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 1 Feb 2026 01:01:27 +0530 Subject: [PATCH] More useful error message when loading image from data fails --- src/calibre/utils/img.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/calibre/utils/img.py b/src/calibre/utils/img.py index c8b3a1d51c..8612baa498 100644 --- a/src/calibre/utils/img.py +++ b/src/calibre/utils/img.py @@ -124,7 +124,14 @@ def image_from_data(data): q = what(None, data) if q == 'jxr': return load_jxr_data(data) - raise NotImage(f'Not a valid image (detected type: {q})') + ba = QByteArray(data) + buf = QBuffer(ba) + buf.open(QIODevice.OpenModeFlag.ReadOnly) + r = QImageReader(buf) + i = r.read() + buf.close() + if i.isNull(): + raise NotImage(f'Not a valid image (detected type: {q}). Error: {r.errorString()}') return i