Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ history.
- DynamicGroup workflow conversion, row editing and validation, including row
templates in node discovery and the widget catalog. Refuse incompatible saved
widget layouts and ambiguous names instead of editing a different widget.
- DynamicGroup refusals carry their own `error.code` in the edit, `apply`,
`foreach`, `slots`, `validate`, `run` and `decompose` envelopes:
`dynamic_group_unsupported`, `dynamic_group_binding_mismatch`,
`dynamic_group_count_out_of_range` and `dynamic_group_rows_linked`, in place
of `workflow_edit_invalid` and the conversion codes. Messages are unchanged.

- `comfy deploy cancel [PATH] [--deployment <name|id>]` ends the update a
deployment waits on and keeps it serving the release it served; `--json`
Expand Down
4 changes: 2 additions & 2 deletions comfy_cli/command/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def execute(
workflow = convert_ui_to_api(raw_workflow, object_info)
except WorkflowConversionError as e:
renderer.error(
code="conversion_error",
code=e.code or "conversion_error",
message=f"Workflow conversion failed: {e}",
hint="use ComfyUI's 'File > Export (API)' to save as API format",
)
Expand Down Expand Up @@ -1012,7 +1012,7 @@ def execute_cloud(
raw_workflow = convert_ui_to_api(raw_workflow, object_info)
except WorkflowConversionError as e:
renderer.error(
code="conversion_error",
code=e.code or "conversion_error",
message=f"Workflow conversion failed: {e}",
hint="use ComfyUI's 'File > Export (API)' to save as API format and retry",
)
Expand Down
7 changes: 6 additions & 1 deletion comfy_cli/command/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,14 @@ def slots_cmd(
input_path, host, port, on_stale=lambda key, err: _stale.update(stale=True, source=key, reason=err)
)

from comfy_cli.cql.engine import DynamicGroupBindingError

template_id = template_id or p.stem
try:
schema = graph.get_template_schema(template_id, workflow)
except DynamicGroupBindingError as e:
renderer.error(code=e.code, message=f"Could not extract slots: {e}")
raise typer.Exit(code=1) from e
except (ValueError, KeyError) as e:
renderer.error(code="workflow_slot_invalid", message=f"Could not extract slots: {e}")
raise typer.Exit(code=1) from e
Expand Down Expand Up @@ -1741,7 +1746,7 @@ def validate_api_workflow(
except WorkflowConversionError as e:
renderer.error(
command=command,
code="workflow_not_api_format",
code=e.code or "workflow_not_api_format",
message=f"Workflow is a UI export that could not be converted to API format: {e}",
hint="use ComfyUI's 'File > Export (API)' to save as API format",
)
Expand Down
14 changes: 10 additions & 4 deletions comfy_cli/command/workflow_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
_load_workflow_or_fail,
_parse_value,
)
from comfy_cli.cql.engine import DynamicGroupBindingError
from comfy_cli.output import get_renderer, rprint

# Shared option aliases — the edit commands (add-node/set-widget/connect/
Expand Down Expand Up @@ -75,7 +76,12 @@ def _emit_edit_error(renderer, e: ValueError, *, hint: str) -> None:
details={k: v for k, v in f.items() if k != "message"},
)
return
renderer.error(code="workflow_edit_invalid", message=str(e), hint=hint)
renderer.error(code=_edit_error_code(e), message=str(e), hint=hint)


def _edit_error_code(e: Exception) -> str:
"""A DynamicGroup refusal keeps its own code; every other edit failure is ``workflow_edit_invalid``."""
return e.code if isinstance(e, DynamicGroupBindingError) else "workflow_edit_invalid"


def _split_addr(addr: str, renderer) -> tuple[Any, str]:
Expand Down Expand Up @@ -915,12 +921,12 @@ def apply_cmd(
"failed": {
"index": getattr(e, "spec_index", None),
"op": getattr(e, "spec_op", None),
"code": "workflow_edit_invalid",
"code": _edit_error_code(e),
},
# Specs applied before the abort — all discarded (atomic batch).
"applied_count": getattr(e, "applied_count", 0),
}
renderer.error(code="workflow_edit_invalid", message=f"batch failed: {e}", details=details)
renderer.error(code=_edit_error_code(e), message=f"batch failed: {e}", details=details)
raise typer.Exit(code=1) from e

workflow_ops.strip_internal(workflow)
Expand Down Expand Up @@ -1093,7 +1099,7 @@ def foreach_cmd(
# leaves the earlier files on disk. Surface them (in the hint AND machine-
# readable details) so the caller isn't blind to the partial output.
renderer.error(
code="workflow_edit_invalid",
code=_edit_error_code(e),
message=f"foreach failed: {e}",
hint=(
f"{len(written)} workflow(s) were written to {out} before the failure — "
Expand Down
2 changes: 1 addition & 1 deletion comfy_cli/command/workflow_fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def decompose_cmd(
api_workflow = convert_ui_to_api(data, object_info)
except WorkflowConversionError as e:
renderer.error(
code="workflow_conversion_failed",
code=e.code or "workflow_conversion_failed",
message=f"Could not convert frontend workflow to API format: {e}",
hint="re-export from ComfyUI, or pass a matching --input object_info.json",
)
Expand Down
47 changes: 32 additions & 15 deletions comfy_cli/cql/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3932,13 +3932,30 @@ def _dynamic_group_widgets(port: Port, prefix: str = "") -> list[Port]:


class DynamicGroupBindingError(ValueError):
pass
"""A DynamicGroup refusal; ``code`` is its ``error.code`` in ``comfy_cli/error_codes.py``.

Raised directly, it means the class's DynamicGroup schema is one this CLI does not support.
"""

code = "dynamic_group_unsupported"


class DynamicGroupLayoutError(DynamicGroupBindingError):
code = "dynamic_group_binding_mismatch"


class DynamicGroupCountError(DynamicGroupBindingError):
code = "dynamic_group_count_out_of_range"


class DynamicGroupLinkedRowsError(DynamicGroupBindingError):
code = "dynamic_group_rows_linked"


def _dynamic_group_row_count(value: Any, available: int, width: int) -> int:
# A corrupt controller must not allocate a roster larger than the saved data.
if isinstance(value, bool) or not isinstance(value, int) or value < 0 or not width or value * width > available:
raise DynamicGroupBindingError("DynamicGroup row count does not match the saved widget values")
raise DynamicGroupLayoutError("DynamicGroup row count does not match the saved widget values")
return value


Expand Down Expand Up @@ -4018,36 +4035,36 @@ def _validate_dynamic_group_layout(node: dict, m: Morphism) -> list[_WidgetEntry
source = values
if "widgets_values_form" in node:
if not isinstance(form, dict) or set(form) != {"order"}:
raise DynamicGroupBindingError("widgets_values_form must contain only an order array")
raise DynamicGroupLayoutError("widgets_values_form must contain only an order array")
order = form["order"]
if not isinstance(order, list) or not order or any(not isinstance(n, str) or not n for n in order):
raise DynamicGroupBindingError("widgets_values_form.order must be a non-empty array of widget names")
raise DynamicGroupLayoutError("widgets_values_form.order must be a non-empty array of widget names")
if isinstance(values, list):
if len(values) != len(order):
raise DynamicGroupBindingError("widgets_values_form length does not match widgets_values")
raise DynamicGroupLayoutError("widgets_values_form length does not match widgets_values")
source = dict(zip(order, values))
elif isinstance(values, dict):
if len(order) != len(set(order)) or any(n not in values for n in order):
raise DynamicGroupBindingError("widgets_values_form has duplicated or missing named values")
raise DynamicGroupLayoutError("widgets_values_form has duplicated or missing named values")
else:
raise DynamicGroupBindingError("widgets_values_form requires array or object widgets_values")
raise DynamicGroupLayoutError("widgets_values_form requires array or object widgets_values")
entries = _expand_widget_entries(m, source if isinstance(source, (list, dict)) else [])
saved_length = len(values) if isinstance(values, list) else len(form["order"]) if form is not None else None
if saved_length is not None:
while len(entries) > saved_length and entries[-1].frontend_injected:
entries.pop()
if form is not None and form["order"] != [e.name for e in entries]:
raise DynamicGroupBindingError("widgets_values_form does not match the available DynamicGroup schema")
raise DynamicGroupLayoutError("widgets_values_form does not match the available DynamicGroup schema")
if isinstance(values, list) and len(entries) != len(values):
raise DynamicGroupBindingError("DynamicGroup schema does not match the saved widget values")
raise DynamicGroupLayoutError("DynamicGroup schema does not match the saved widget values")
for index, entry in enumerate(entries):
if entry.owner is None or entry.port is None or entry.port.raw_spec is not None:
continue
if isinstance(source, dict) and entry.name not in source:
continue
companion = source[entry.name] if isinstance(source, dict) else source[index]
if entry.port.validate_shape(companion) or entry.port.validate_catalog(companion):
raise DynamicGroupBindingError(f"DynamicGroup companion {entry.name!r} must use a supported control mode")
raise DynamicGroupLayoutError(f"DynamicGroup companion {entry.name!r} must use a supported control mode")
return entries


Expand Down Expand Up @@ -4108,7 +4125,7 @@ def emit(name: str, port: Port, owner: str | None, depth: int) -> None:
):
rows.add(row)
if rows and name not in widgets_values:
raise DynamicGroupBindingError(f"DynamicGroup controller {name!r} is missing for saved rows")
raise DynamicGroupLayoutError(f"DynamicGroup controller {name!r} is missing for saved rows")
count = _dynamic_group_row_count(saved_value(name, idx, 0), len(rows), 1)
limit = str(count)
count = _dynamic_group_row_count(count, sum((len(row), row) < (len(limit), limit) for row in rows), 1)
Expand Down Expand Up @@ -4456,7 +4473,7 @@ def _write_widget(node: dict, input_name: str, value: Any, graph: Graph, *, exte
group_entries = _validate_dynamic_group_layout(node, m)
has_group = group_entries is not None
if has_group and "widgets_values_named" in node and not isinstance(node["widgets_values_named"], dict):
raise ValueError("widgets_values_named must be an object before editing widgets")
raise DynamicGroupLayoutError("widgets_values_named must be an object before editing widgets")
raw_values = node.get("widgets_values")
widgets = _widgets_as_positional(node.get("widgets_values"), graph, node_type)
order = graph.widget_order_for_node(node_type, widgets)
Expand Down Expand Up @@ -4526,7 +4543,7 @@ def _write_dynamic_group_count(
minimum = port.options.min if port.options.min is not None else 0
maximum = port.options.max if port.options.max is not None else 20
if isinstance(count, bool) or not isinstance(count, int) or not minimum <= count <= maximum:
raise ValueError(f"{port.name}: row count must be an integer between {minimum} and {maximum}")
raise DynamicGroupCountError(f"{port.name}: row count must be an integer between {minimum} and {maximum}")
if "inputs" in node and (
not isinstance(node["inputs"], list) or any(not isinstance(inp, dict) for inp in node["inputs"])
):
Expand All @@ -4542,14 +4559,14 @@ def _write_dynamic_group_count(
names = {p.name for p in new_fields}
removed = {e.name for e in old_entries} - names
if any(i.get("name") in removed and i.get("link") is not None for i in node.get("inputs", [])):
raise ValueError(f"{port.name}: disconnect the removed rows before reducing their count")
raise DynamicGroupLinkedRowsError(f"{port.name}: disconnect the removed rows before reducing their count")
surviving_inputs = [
(index, inp) for index, inp in enumerate(node.get("inputs") or []) if inp.get("name") not in removed
]
if any(
inp.get("link") is not None and previous != current for current, (previous, inp) in enumerate(surviving_inputs)
):
raise ValueError(f"{port.name}: disconnect shifted inputs before reducing their count")
raise DynamicGroupLinkedRowsError(f"{port.name}: disconnect shifted inputs before reducing their count")
old_names = {e.name for e in old_entries}
new_values = {
p.name: old_values[p.name] if p.name in old_values else _widget_default(p)
Expand Down
23 changes: 22 additions & 1 deletion comfy_cli/error_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,30 @@ class ErrorCode:
"dynamic_group_unsupported",
"A node class has a DynamicGroup schema this CLI does not support, so `comfy nodes widget-catalog` "
"left it out of `types`. Consumers store that class's values opaquely and refuse widget writes to it. "
"Surfaced in `data.warnings[]` (not as an error envelope) so every other class is still published.",
"Surfaced in `data.warnings[]` (not as an error envelope) so every other class is still published. "
"The workflow edit commands, `workflow apply`/`foreach`, `workflow slots`, `workflow validate`, `run` "
"and `workflow decompose` raise it as the error code when a workflow uses such a class; nothing is "
"written.",
"update comfy-cli, or leave the class's widgets unedited",
),
ErrorCode(
"dynamic_group_binding_mismatch",
"A node's saved DynamicGroup values do not bind to its class's DynamicGroup schema: the saved row count "
"or controller disagrees with the saved rows, `widgets_values_form` or `widgets_values_named` is "
"malformed or disagrees with the schema, or a row's seed control mode is unsupported. Raised by the same "
"commands as `dynamic_group_unsupported`, before anything is read or written.",
"re-save the workflow in a ComfyUI frontend whose node schema matches the catalog, then retry",
),
ErrorCode(
"dynamic_group_count_out_of_range",
"A DynamicGroup row-count write was not an integer between the group's `min` and `max`. Nothing was written.",
"read the group's `min`/`max` from `comfy nodes widget-catalog` (`dynamic_groups`) and write a count in range",
),
ErrorCode(
"dynamic_group_rows_linked",
"Reducing a DynamicGroup row count would drop or shift a row input that has a link. Nothing was written.",
"disconnect the links into the rows being removed or shifted, then reduce the count",
),
ErrorCode(
"description_ignored",
"`comfy workflow save --where local --description` was given a description, but the local "
Expand Down
3 changes: 2 additions & 1 deletion comfy_cli/workflow_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ def _rehint_discarded_batch(e: Exception, pre_batch_hint: str) -> ValueError:
"Any node id minted by this batch is gone; re-read ids with "
"`comfy workflow slots` / `ls-nodes` before addressing nodes."
)
return ValueError(msg + suffix)
# A DynamicGroup refusal keeps its class, and with it its ``code``.
return (type(e) if isinstance(e, DynamicGroupBindingError) else ValueError)(msg + suffix)


def _find_by_str(workflow: dict, node_id: Any) -> dict | None:
Expand Down
11 changes: 9 additions & 2 deletions comfy_cli/workflow_to_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@


class WorkflowConversionError(Exception):
"""Raised when a workflow can't be converted to API format."""
"""Raised when a workflow can't be converted to API format.

``code`` is the refusal's own ``error.code`` when it has one (a DynamicGroup refusal), else None.
"""

def __init__(self, message: str, code: str | None = None):
super().__init__(message)
self.code = code


def is_api_format(workflow: Any) -> bool:
Expand Down Expand Up @@ -183,7 +190,7 @@ def convert_ui_to_api(workflow: dict, object_info: dict) -> dict:
nodes_to_exclude=nodes_to_exclude,
)
except DynamicGroupBindingError as exc:
raise WorkflowConversionError(f"Node {node_id_str} ({node_type}): {exc}") from exc
raise WorkflowConversionError(f"Node {node_id_str} ({node_type}): {exc}", exc.code) from exc
except Exception:
# An individual malformed node should not torpedo the whole prompt.
# The executor will fail loudly on missing nodes if this matters.
Expand Down
Loading
Loading