diff --git a/nodes/ideogram4_nodes.py b/nodes/ideogram4_nodes.py index 2250743..ca3b647 100644 --- a/nodes/ideogram4_nodes.py +++ b/nodes/ideogram4_nodes.py @@ -210,7 +210,14 @@ def save_bg_image_to_temp(guid, image): exc, raw_guid, ) return None - pil = _tensor_to_pil(image) + try: + pil = _tensor_to_pil(image) + except Exception as exc: + _bg_warn( + "background image was not saved: could not convert the image tensor (guid=%s): %s", + safe_guid, exc, + ) + return None if pil is None: _bg_warn("background image was not saved: could not convert the image tensor (guid=%s)", safe_guid) return None diff --git a/tests/test_nodes.py b/tests/test_nodes.py index 929db69..e7169d8 100644 --- a/tests/test_nodes.py +++ b/tests/test_nodes.py @@ -2,6 +2,7 @@ import json import unittest +from unittest.mock import MagicMock, patch # conftest.py handles mocking and path setup from nodes.ideogram4_nodes import ( @@ -400,6 +401,16 @@ class TestPromptHelpers(unittest.TestCase): self.assertIsNone(result) self.assertTrue(any("invalid background guid" in line.lower() for line in cm.output)) + def test_save_bg_image_warns_when_conversion_fails(self): + guid = "12345678-1234-4abc-8abc-123456789012" + image_mod = save_bg_image_to_temp.__globals__["Image"] + with patch.object(image_mod, "fromarray", side_effect=ValueError("bad shape")): + with self.assertLogs("byae.ideogram.bg", level="WARNING") as cm: + result = save_bg_image_to_temp(guid, MagicMock()) + self.assertIsNone(result) + self.assertTrue(any("could not convert" in line.lower() for line in cm.output)) + self.assertTrue(any("bad shape" in line for line in cm.output)) + class TestPromptAssembly(unittest.TestCase): """Test full prompt assembly logic without ComfyUI runtime."""