chore: tighten error handling and dedupe a magic string from the nitpick pass
- Narrow the ProgressBar import guard to ImportError only, with a comment explaining why it stays (the module is imported standalone by the test suite outside a live ComfyUI) - Extract the CRAFTKIT_DIALOG_ERROR: sentinel into a shared constant instead of three separate literals, use str.removeprefix - Note that .avif/.heic can also fail on re-encode (with output_format=keep_source), not just decode
This commit is contained in:
+7
-2
@@ -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})
|
||||
|
||||
@@ -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"}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user