affaan-m/ECC · error · ValueError

frame/count must be an exact integer in range

Error message

frame/count must be an exact integer in range

What it means

_integer requires an exact int (bool excluded via type() check) greater than or equal to the minimum (default 0); anything else raises ValueError('frame/count must be an exact integer in range'). Frame indices and counts in the bundle must be exact whole numbers.

Solutions

  1. Coerce numeric values with int(v) and verify v == int(v) before building the bundle
  2. Convert numpy scalars with .item()/int() so they become Python ints
  3. Check for negative values in range/duration computations and clamp or fix the source math

Example fix

// before
snapshot = {"duration_frames": 240.0, ...}
// after
snapshot = {"duration_frames": int(240.0), ...}
Defensive patterns

Strategy: type-guard

Validate before calling

def as_frame(v):
    if isinstance(v, bool) or not isinstance(v, int) or v < 0:
        raise TypeError(f"not a frame int: {v!r}")
    return v

Type guard

def is_frame_int(v) -> bool:
    return type(v) is int and v >= 0

Try / catch

try:
    bundle = build_application_bundle(data)
except ValueError as e:
    if "exact integer" in str(e):
        print("frame/count field is not an exact int; coerce floats/numpy types")
    else:
        raise

Prevention

When it happens

Trigger: Passing a float like 24.0, a bool, a string '24', or a negative frame number to any frame/count field (range endpoints, durations, rates' numerator/denominator with minimum 1).

Common situations: JSON parsers or APIs that produce floats for whole numbers, numpy integer types (np.int64) that fail the exact type() check, and negative values from off-by-one frame math.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/4e45077dfdb4c983. Report an issue: GitHub.

Appendix: source

Thrown at skills/taste-application/scripts/tasteforge/integration.py:55


def _object(value: Any, required: set[str], optional: set[str] | None = None) -> dict:
    if not isinstance(value, dict) or not required <= value.keys():
        raise ValueError("missing required bundle fields")
    if value.keys() - required - (optional or set()):
        raise ValueError("unknown bundle fields")
    return value


def _text(value: Any) -> str:
    if not isinstance(value, str) or not value.strip():
        raise ValueError("nonempty text required")
    return value


def _integer(value: Any, minimum: int = 0) -> int:
    if type(value) is not int or value < minimum:
        raise ValueError("frame/count must be an exact integer in range")
    return value


def _rate(value: Any) -> tuple[int, int]:
    _object(value, {"numerator", "denominator"})
    n, d = (_integer(value[k], 1) for k in ("numerator", "denominator"))
    if math.gcd(n, d) != 1:
        raise ValueError("fps must be a reduced positive rational")
    return n, d


def _range(value: Any, bounds: list[int] | None = None) -> list[int]:
    if not isinstance(value, list) or len(value) != 2:
        raise ValueError("range must contain two frame integers")
    start, end = (_integer(v) for v in value)
    if start >= end or (bounds is not None and (start < bounds[0] or end > bounds[1])):
        raise ValueError("frame range is empty or outside its bounds")
    return value

View on GitHub (pinned to 8321021c54)