{"record":{"id":"c00266e221af1d53","repo":"Comfy-Org/ComfyUI","slug":"cannot-convert-empty-string-to-number","errorCode":null,"errorMessage":"Cannot convert empty string to number.","messagePattern":"Cannot convert empty string to number\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_number_convert.py","lineNumber":56,"sourceCode":"                io.Int.Output(display_name=\"INT\"),\n            ],\n        )\n\n    @classmethod\n    def execute(cls, value) -> io.NodeOutput:\n        if isinstance(value, bool):\n            float_val = 1.0 if value else 0.0\n            int_val = 1 if value else 0\n        elif isinstance(value, int):\n            float_val = float(value)\n            int_val = value\n        elif isinstance(value, float):\n            float_val = value\n            int_val = int(value)\n        elif isinstance(value, str):\n            text = value.strip()\n            if not text:\n                raise ValueError(\"Cannot convert empty string to number.\")\n            try:\n                float_val = float(text)\n            except ValueError:\n                raise ValueError(\n                    f\"Cannot convert string to number: {value!r}\"\n                ) from None\n            if not math.isfinite(float_val):\n                raise ValueError(\n                    f\"Cannot convert non-finite value to number: {float_val}\"\n                )\n            try:\n                int_val = int(text)\n            except ValueError:\n                int_val = int(float_val)\n        else:\n            raise TypeError(\n                f\"Unsupported input type: {type(value).__name__}\"\n            )","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_number_convert.py#L38-L74","documentation":"Raised by the number-conversion node when the input value is a string that is empty or contains only whitespace after .strip(). The node refuses to guess a numeric value for blank text rather than silently converting to 0.","triggerScenarios":"Feeding a STRING input (e.g. from a text node or primitive) whose value is '', '   ', or '\\t\\n' into the number converter. Only the string branch with not text after stripping triggers this.","commonSituations":"UI text fields left empty and wired into a number input; prompt templates that render an empty placeholder; API workflows where a variable interpolates to nothing.","solutions":["Provide an actual numeric string such as '1.5' or '42'.","Insert a default-value/string-handling node upstream so empty text becomes a chosen fallback before conversion.","Validate string inputs are non-empty before connecting them to the converter."],"exampleFix":"// before\nNumberConvert(value=\"   \")\n// after\nNumberConvert(value=\"0\")","handlingStrategy":"validation","validationCode":"if isinstance(value, str) and not value.strip():\n    value = \"0\"  # or raise your own descriptive error before the node sees it","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default text primitives to '0' instead of empty when they feed number conversions.","Validate string inputs are non-empty in API payloads before submitting prompts."],"tags":["type-conversion","string","number","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}