Nodes/ComfyUI_Swwan/Raise Exception On True
ComfyUI Node

Raise Exception On True

Kill a ComfyUI run the moment a check fails

By aining2022·Created 9 months ago·Updated 10 days ago· 33
Raise Exception On True
    • condition
    conditionfalse
    exception_messageWorkflow terminated by condition.

    raiseExceptionOnTrue is a tripwire. You wire up a boolean condition, and if it ever comes out True, it raises an exception that kills the entire run - on purpose. That's the whole job, and for something that sounds like a debugging leftover it saves more GPU time than most nodes twice its size.

    Think of it as an assert in graph form, except you get to write the error message. ComfyUI has no try/catch and no "stop and ask me" - a failed run just aborts. This node turns that failure into a deliberate, readable one instead of letting you discover an hour later that frame 40 was garbage.

    Why you'd reach for it

    You use it downstream of anything that emits a boolean and upstream of anything expensive. The pattern: a check node decides the workflow is doomed (wrong batch size, an empty mask, a count mismatch after a crop step, a value out of range), True flows into this node, and the run stops before the sampler burns ten minutes producing output you'd delete anyway.

    Where people actually put it: after an image-count or dimension check, before a video pass, or right after a condition you set manually when you're iterating on a workflow and want it to hard-fail early instead of silently producing broken frames.

    How it works

    The source is almost insultingly short:

    def check_and_raise(self, condition, exception_message="Workflow terminated by condition."):
        if condition:
            raise Exception(exception_message)
        return (condition,)
    

    When condition is False it's a pass-through - it returns the boolean unchanged so the graph keeps flowing. When it's True, the exception propagates, the queue aborts, and the message shows up in your console/log.

    The inputs that matter are just the two you see:

    • condition (BOOLEAN, default false) - the thing being tested.
    • exception_message (STRING, default "Workflow terminated by condition.") - the error text. Set it to something you'll recognize, like "mask is empty - check your load order".

    The single output is condition itself, so you can keep the boolean flowing to other logic if the run survives.

    Install

    It ships in the ComfyUI_Swwan pack. In ComfyUI Manager, search "ComfyUI_Swwan" and install, or do it by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/aining2022/ComfyUI_Swwan
    cd ComfyUI_Swwan
    pip install -r requirements.txt
    

    Restart ComfyUI and you'll find it under Swwan/utils. No model downloads, no API keys - this is pure Python.

    The gotchas

    The big one is the design intent: this is a hard stop. There's no way to catch the error and route around it inside the graph, so don't put it in the middle of a long queue expecting the remaining jobs to continue. If it fires, everything after it is cancelled. That's the feature, but it's also why you keep the condition tight.

    If you see Workflow terminated by condition. in the console, that's not a crash to debug - it's the tripwire firing. Flip the upstream condition and re-run. The other trap: a boolean that's False because a node silently didn't run (returns None) will not trip this node - you'll want to check for that upstream, or this does nothing at all.

    One more note: this node just raises. It's not a switch and it won't reroute anything - if you need "if bad, use plan B", that's what rgthree-style switch nodes are for. This one is for "if bad, stop".

    CategorySwwan/utils

    Inputs (2)

    NameTypeDefaultDescription
    conditionBOOLEANfalse
    exception_messageSTRINGWorkflow terminated by condition.

    Outputs (1)

    NameTypeDescription
    conditionBOOLEAN