heygen-com/hyperframes · error · RangeError

A color curve requires at least two points

Error message

A color curve requires at least two points

What it means

validateCurvePoints() requires at least two control points to interpolate a curve; fewer than two is rejected as a RangeError. A single point (or zero) cannot define a segment, so cubic Hermite interpolation — which needs a start and end — has nothing to operate on. Applies to both compileHfColorCurve and the periodic hue path (which extends points but still calls validateCurvePoints).

Source

Thrown at packages/core/src/colorGradingCurves.ts:73

  for (let index = 1; index < points.length - 1; index += 1) {
    const before = valueAt(slopes, index - 1);
    const after = valueAt(slopes, index);
    if (before === 0 || after === 0 || Math.sign(before) !== Math.sign(after)) {
      result[index] = 0;
      continue;
    }
    const beforeSpan = valueAt(spans, index - 1);
    const afterSpan = valueAt(spans, index);
    const beforeWeight = 2 * afterSpan + beforeSpan;
    const afterWeight = afterSpan + 2 * beforeSpan;
    result[index] = (beforeWeight + afterWeight) / (beforeWeight / before + afterWeight / after);
  }
  return result;
}

function validateCurvePoints(points: readonly HfColorCurvePoint[], size: number): void {
  if (points.length < 2) throw new RangeError("A color curve requires at least two points");
  if (!Number.isInteger(size) || size < 2) {
    throw new RangeError("Curve LUT size must be at least 2");
  }
  let previousInput = Number.NEGATIVE_INFINITY;
  for (const [input, output] of points) {
    if (!Number.isFinite(input) || !Number.isFinite(output)) {
      throw new TypeError("Color curve points must be finite");
    }
    if (input <= previousInput) {
      throw new RangeError("Color curve inputs must be strictly increasing");
    }
    previousInput = input;
  }
}

function validateOutputRange(
  points: readonly HfColorCurvePoint[],
  outputMin: number,

View on GitHub (pinned to c2996c8626)

Solutions

  1. Supply at least two points; for a color curve the canonical minimum is the two endpoints [[0,0],[1,1]] (identity).
  2. Guard in the UI: disable render until the user has placed >= 2 points.

Example fix

// before
const lut = compileHfColorCurve([[0, 0]]); // < 2 points

// after — identity curve with both endpoints
const lut = compileHfColorCurve([[0, 0], [1, 1]]);
Defensive patterns

Strategy: validation

Validate before calling

if (points.length < 2) throw new Error('need >= 2 curve points');
// or default to the identity curve
const safe = points.length >= 2 ? points : [[0,0],[1,1]] as const;

Type guard

function hasEnoughPoints<T>(pts: readonly T[]): pts is [T, T, ...T[]] {
  return pts.length >= 2;
}

Try / catch

try { compileHfColorCurve(pts); }
catch (err) { if (/at least two points/.test(String(err))) { pts = [[0,0],[1,1]]; } else throw err; }

Prevention

When it happens

Trigger: Calling compileHfColorCurve([]) or compileHfColorCurve([[0,0]]) with 0 or 1 points; a UI that lets a user clear all but one point and then renders.

Common situations: A color-grade tool defaulting to an empty points array before the user adds any; programmatic curve construction that forgot endpoints; a deserialization that dropped points.

Related errors


AI-assisted analysis of heygen-com/hyperframes@c2996c8626 (2026-08-12). Data as JSON: /api/errors/97b28de6758b701c. Report an issue: GitHub.