diff --git a/__init__.py b/__init__.py index d3cf770..aefc9e5 100644 --- a/__init__.py +++ b/__init__.py @@ -20,6 +20,10 @@ try: from server import PromptServer _dialog_lock = threading.Lock() + # Must match the literal 'CRAFTKIT_DIALOG_ERROR:' prefix written by the + # PowerShell catch block below (kept literal there to avoid brace-escaping + # a dense here-string). + _DIALOG_ERROR_PREFIX = "CRAFTKIT_DIALOG_ERROR:" async def browse_folder(request): import subprocess, sys @@ -128,6 +132,7 @@ $o.Add_Shown({ $path = [CraftKitFolderPicker]::ShowDialog($o.Handle, 'Select input folder') if ($path) { $script:r = $path } } catch { + # Must match _DIALOG_ERROR_PREFIX in __init__.py. $script:r = 'CRAFTKIT_DIALOG_ERROR:' + $_.Exception.Message } $o.Close() @@ -153,8 +158,8 @@ $r finally: _dialog_lock.release() - if folder.startswith("CRAFTKIT_DIALOG_ERROR:"): - return web.json_response({"ok": False, "error": folder[len("CRAFTKIT_DIALOG_ERROR:"):]}, status=500) + if folder.startswith(_DIALOG_ERROR_PREFIX): + return web.json_response({"ok": False, "error": folder.removeprefix(_DIALOG_ERROR_PREFIX)}, status=500) if folder and os.path.isdir(folder): return web.json_response({"ok": True, "path": folder}) diff --git a/smart_batch_resize.py b/smart_batch_resize.py index 06d45e8..460f38a 100644 --- a/smart_batch_resize.py +++ b/smart_batch_resize.py @@ -6,8 +6,11 @@ import numpy as np import torch try: + # Only unavailable when this module is imported standalone outside a live + # ComfyUI process (e.g. the test suite); ImportError is the only expected + # failure here, so anything else is left to surface normally. from comfy.utils import ProgressBar -except Exception: +except ImportError: ProgressBar = None @@ -18,9 +21,9 @@ INTERP_MAP = { "nearest": PILImage.NEAREST, } -# .avif/.heic decoding depends on optional Pillow plugins that may not be installed; -# if unsupported, the per-file try/except below skips that file with a clear warning -# instead of crashing the batch. +# .avif/.heic decoding (and, with output_format=keep_source, re-encoding) depends on +# optional Pillow plugins that may not be installed; if unsupported, the per-file +# try/except below skips that file with a clear warning instead of crashing the batch. SUPPORTED_EXT = {".png", ".jpg", ".jpeg", ".jfif", ".webp", ".bmp", ".tiff", ".tif", ".avif", ".heic"}