{"record":{"id":"605e697cbe5890e1","repo":"Comfy-Org/ComfyUI","slug":"invalid-operation-operation-for-morphology-must","errorCode":null,"errorMessage":"Invalid operation {operation} for morphology. Must be one of 'erode', 'dilate', 'open', 'close', 'gradient', 'tophat', 'bottomhat'","messagePattern":"Invalid operation (.+?) for morphology\\. Must be one of 'erode', 'dilate', 'open', 'close', 'gradient', 'tophat', 'bottomhat'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_morphology.py","lineNumber":51,"sourceCode":"        device = comfy.model_management.get_torch_device()\n        kernel = torch.ones(kernel_size, kernel_size, device=device)\n        image_k = image.to(device).movedim(-1, 1)\n        if operation == \"erode\":\n            output = erosion(image_k, kernel)\n        elif operation == \"dilate\":\n            output = dilation(image_k, kernel)\n        elif operation == \"open\":\n            output = opening(image_k, kernel)\n        elif operation == \"close\":\n            output = closing(image_k, kernel)\n        elif operation == \"gradient\":\n            output = gradient(image_k, kernel)\n        elif operation == \"top_hat\":\n            output = top_hat(image_k, kernel)\n        elif operation == \"bottom_hat\":\n            output = bottom_hat(image_k, kernel)\n        else:\n            raise ValueError(f\"Invalid operation {operation} for morphology. Must be one of 'erode', 'dilate', 'open', 'close', 'gradient', 'tophat', 'bottomhat'\")\n        img_out = output.to(comfy.model_management.intermediate_device()).movedim(1, -1)\n        return io.NodeOutput(img_out)\n\n\nclass ImageRGBToYUV(io.ComfyNode):\n    @classmethod\n    def define_schema(cls):\n        return io.Schema(\n            node_id=\"ImageRGBToYUV\",\n            search_aliases=[\"color space conversion\"],\n            display_name=\"Image RGB to YUV\",\n            category=\"image/color\",\n            inputs=[\n                io.Image.Input(\"image\"),\n            ],\n            outputs=[\n                io.Image.Output(display_name=\"Y\"),\n                io.Image.Output(display_name=\"U\"),","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_morphology.py#L33-L69","documentation":"Raised by the Morphology node when the operation string matches none of the if/elif branches. The combo UI restricts choices, but the API accepts any string, so only out-of-band values reach this raise. Note: the message lists 'tophat'/'bottomhat' but the code (and combo options) actually require 'top_hat'/'bottom_hat' with underscores — the message is misleading.","triggerScenarios":"Calling the Morphology node via the HTTP API or a hand-edited workflow with an operation value outside {erode, dilate, open, close, gradient, top_hat, bottom_hat}. Copying the error message's own suggestion 'tophat' or 'bottomhat' will fail again because the code compares against 'top_hat'/'bottom_hat'.","commonSituations":"Scripts POSTing prompts to /prompt with a typo'd operation; workflows authored outside the UI; users following the error text verbatim and hitting the same error.","solutions":["Use one of the exact accepted strings: 'erode', 'dilate', 'open', 'close', 'gradient', 'top_hat', 'bottom_hat' (underscores, despite what the message says).","If driving via API, validate the operation against the node's combo options from /object_info before submitting.","Patch the node to fix the misleading error message text."],"exampleFix":"// before\n{\"class_type\": \"Morphology\", \"inputs\": {\"image\": [...], \"operation\": \"tophat\", \"kernel_size\": 3}}\n// after\n{\"class_type\": \"Morphology\", \"inputs\": {\"image\": [...], \"operation\": \"top_hat\", \"kernel_size\": 3}}","handlingStrategy":"validation","validationCode":"VALID_MORPH_OPS = {'erode', 'dilate', 'open', 'close', 'gradient', 'top_hat', 'bottom_hat'}\nif operation not in VALID_MORPH_OPS:\n    raise ValueError(f\"operation must be one of {sorted(VALID_MORPH_OPS)}\")","typeGuard":"def is_valid_morph_op(op: str) -> bool:\n    return op in {'erode', 'dilate', 'open', 'close', 'gradient', 'top_hat', 'bottom_hat'}","tryCatchPattern":null,"preventionTips":["Pull combo options from /object_info/Morphology instead of hardcoding strings in API scripts.","Remember the accepted values use underscores ('top_hat'), regardless of the error message text."],"tags":["morphology","kornia","image-processing","invalid-argument","error-message-mismatch"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}