From a809de8970d48f8c878144d6c2f2d5f1a92f15cb Mon Sep 17 00:00:00 2001 From: Debanjum Date: Mon, 13 Oct 2025 15:42:43 -0400 Subject: [PATCH] Handle skip indexing of unsupported image files Previously unsupported image file types would trigger an unbound local variable error. --- src/khoj/processor/content/images/image_to_entries.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/khoj/processor/content/images/image_to_entries.py b/src/khoj/processor/content/images/image_to_entries.py index ea896e59..b5b1fffa 100644 --- a/src/khoj/processor/content/images/image_to_entries.py +++ b/src/khoj/processor/content/images/image_to_entries.py @@ -54,6 +54,7 @@ class ImageToEntries(TextToEntries): entries: List[str] = [] entry_to_location_map: List[Tuple[str, str]] = [] for image_file in image_files: + tmp_file = None try: bytes = image_files[image_file] # write the image to a temporary file @@ -65,6 +66,8 @@ class ImageToEntries(TextToEntries): tmp_file = f"tmp_image_file_{timestamp_now}.jpg" elif image_file.endswith(".webp"): tmp_file = f"tmp_image_file_{timestamp_now}.webp" + else: + continue with open(tmp_file, "wb") as f: bytes = image_files[image_file] f.write(bytes) @@ -89,7 +92,7 @@ class ImageToEntries(TextToEntries): logger.warning(f"Unable to process file: {image_file}. This file will not be indexed.") logger.warning(e, exc_info=True) finally: - if os.path.exists(tmp_file): + if tmp_file and os.path.exists(tmp_file): os.remove(tmp_file) return file_to_text_map, ImageToEntries.convert_image_entries_to_maps(entries, dict(entry_to_location_map))