From 86b6ed1f75b80a6b57d357ecb4c040b9d278572a Mon Sep 17 00:00:00 2001
From: Henry Lindeman <hmlindeman@yahoo.com>
Date: Thu, 5 Dec 2024 14:46:12 -0800
Subject: [PATCH] don't die if box is None in try_draw_boxes (#1060)

* don't die if box is None in try_draw_boxes

Signed-off-by: Henry Lindeman <hmlindeman@yahoo.com>

* fix ruff

Signed-off-by: Henry Lindeman <hmlindeman@yahoo.com>

---------

Signed-off-by: Henry Lindeman <hmlindeman@yahoo.com>
---
 lib/sycamore/sycamore/utils/image_utils.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/sycamore/sycamore/utils/image_utils.py b/lib/sycamore/sycamore/utils/image_utils.py
index 346c502cc..2894c4cff 100644
--- a/lib/sycamore/sycamore/utils/image_utils.py
+++ b/lib/sycamore/sycamore/utils/image_utils.py
@@ -3,6 +3,7 @@
 from packaging.version import InvalidVersion, Version
 from pathlib import Path
 from typing import Any, Callable, Optional, TypeVar, Union
+import logging
 import PIL
 from PIL import Image, ImageDraw, ImageFont
 from sycamore.data import Document
@@ -198,7 +199,11 @@ def try_draw_boxes(
         font = ImageFont.load_default()
 
     for i, box in enumerate(boxes):
-        raw_coords = coord_fn(box)
+        try:
+            raw_coords = coord_fn(box)
+        except Exception:
+            logging.warn(f"Could not extract bbox coords from {box}")
+            continue
 
         # If the coordinates are all less than or equal to 1.0, then we treat them
         # as relative coordinates, and we convert them to absolute coordinates.