Comfy-Org/ComfyUI · error · ValueError
Cannot convert non-finite value to number: {float_val}
Error message
Cannot convert non-finite value to number: {float_val} What it means
Raised inside the string branch of the number-conversion node when float(text) succeeds but the result is NaN or ±Infinity (math.isfinite fails). This catches strings like 'nan', 'inf', '-infinity' which parse but cannot represent a usable workflow number.
Source
Thrown at comfy_extras/nodes_number_convert.py:64
int_val = 1 if value else 0
elif isinstance(value, int):
float_val = float(value)
int_val = value
elif isinstance(value, float):
float_val = value
int_val = int(value)
elif isinstance(value, str):
text = value.strip()
if not text:
raise ValueError("Cannot convert empty string to number.")
try:
float_val = float(text)
except ValueError:
raise ValueError(
f"Cannot convert string to number: {value!r}"
) from None
if not math.isfinite(float_val):
raise ValueError(
f"Cannot convert non-finite value to number: {float_val}"
)
try:
int_val = int(text)
except ValueError:
int_val = int(float_val)
else:
raise TypeError(
f"Unsupported input type: {type(value).__name__}"
)
if not math.isfinite(float_val):
raise ValueError(
f"Cannot convert non-finite value to number: {float_val}"
)
return io.NodeOutput(float_val, int_val)
View on GitHub (pinned to 1c6d8d45b3)
Solutions
- Replace the value with a finite number (e.g. a large but finite bound like 1e6 instead of 'inf').
- Sanitize upstream computations that produce NaN so they emit a real default.
- Use the node's plain number inputs instead of strings when you need large values.
Example fix
// before NumberConvert(value="inf") // after NumberConvert(value="1000000")
Defensive patterns
Strategy: validation
Validate before calling
import math
text = text.strip()
try:
v = float(text)
except ValueError:
raise ValueError(f"not a number: {text!r}")
if not math.isfinite(v):
raise ValueError(f"non-finite value not allowed: {text!r}") Type guard
def is_finite_number_string(text: str) -> bool:
try:
return math.isfinite(float(text.strip()))
except ValueError:
return False Prevention
- Never use 'inf'/'nan' strings as sentinels through this node.
- Bound 'unlimited' values with large finite constants like 1e6.
When it happens
Trigger: Input strings 'nan', 'NaN', 'inf', '-inf', '+Infinity', or float-overflowing scientific notation such as '1e999' (parses to inf). Only in the string branch, immediately after float_val is computed.
Common situations: Upstream math or data pipelines emitting NaN/Inf as text; placeholder sentinel values like 'inf' used for 'no limit'; hand-typed scientific notation that overflows float64.
Related errors
- Keyframe times must be finite numbers in seconds; got '{valu
- Cannot convert empty string to number.
- Unsupported input type: {type(value).__name__}
- Math Expression '{expression}' produced a non-finite result:
- Cannot convert string to number: {value!r}
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/bb7c702f039ddae5.
Report an issue: GitHub.