remotion-dev/remotion · error · TypeError

maxRetries cannot be negative but is ${maxRetries}

Error message

maxRetries cannot be negative but is ${maxRetries}

What it means

Thrown by validateMaxRetries() when maxRetries is a finite number but is less than 0. Retries cannot be negative, so the validator rejects any negative value after confirming type, finiteness, and non-NaN.

Source

Thrown at packages/cloudrun/src/shared/validate-retries.ts:19

export function validateMaxRetries(
	maxRetries: unknown,
): asserts maxRetries is number {
	if (typeof maxRetries !== 'number') {
		throw new TypeError(
			'maxRetries must be a number, but is ' + JSON.stringify(maxRetries),
		);
	}

	if (!Number.isFinite(maxRetries)) {
		throw new TypeError('maxRetries must be finite, but is ' + maxRetries);
	}

	if (Number.isNaN(maxRetries)) {
		throw new TypeError('maxRetries is NaN');
	}

	if (maxRetries < 0) {
		throw new TypeError(`maxRetries cannot be negative but is ${maxRetries}`);
	}

	if (maxRetries % 1 !== 0) {
		throw new TypeError(
			`maxRetries should be an integer, but is ${maxRetries}.`,
		);
	}
}

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Clamp the value to a minimum of 0: Math.max(0, value).
  2. Re-check the arithmetic that produces maxRetries for an inverted subtraction.
  3. Use a literal (0 is valid) when you want to disable retries.

Example fix

// before
const maxRetries = current - budget; // can be negative

// after
const maxRetries = Math.max(0, current - budget);
Defensive patterns

Strategy: validation

Validate before calling

if (typeof maxRetries === 'number' && maxRetries < 0) {
  throw new RangeError(`maxRetries cannot be negative: ${maxRetries}`);
}

Type guard

const isNonNegativeInt = (v: unknown): v is number =>
  typeof v === 'number' && Number.isInteger(v) && v >= 0;

Prevention

When it happens

Trigger: Passing a negative retry count, often the result of subtracting a larger number from a smaller one, or flipping a sign incorrectly.

Common situations: Computing retries as a difference (e.g. attempt - maxAttempts) that goes negative; off-by-one in a decrement loop; user input parsed with an erroneous minus sign.

Related errors


AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12). Data as JSON: /api/errors/310b92df77217569. Report an issue: GitHub.