earendil-works/pi · error · TypeError

Eval input arrays must not be sparse.

Error message

Eval input arrays must not be sparse.

What it means

TypeError thrown by canonicalizeJson when an array in the eval input has holes (missing indices), which Object.hasOwn detects during canonicalization; sparse arrays have no stable JSON representation.

Solutions

  1. Fill sparse array holes with explicit values (e.g. null)
  2. Build arrays with push/assign so no indices are skipped
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/evals/src/vitest-evals/harness-table.ts:80 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/fc2309003fa9ee8f. Report an issue: GitHub.

Appendix: source

Thrown at packages/evals/src/vitest-evals/harness-table.ts:80

	}
	return { schemaVersion, evalSet, groupKey, harness, baseline, candidates, repetition };
}

function canonicalizeJson(value: unknown, ancestors: WeakSet<object>): JsonValue {
	if (value === null || typeof value === "string" || typeof value === "boolean") return value;
	if (typeof value === "number") {
		if (!Number.isFinite(value)) throw new TypeError("Eval input must contain only finite numbers.");
		return value;
	}
	if (typeof value !== "object") throw new TypeError("Eval input must be JSON-serializable.");
	if (ancestors.has(value)) throw new TypeError("Eval input must not contain circular references.");

	ancestors.add(value);
	try {
		if (Array.isArray(value)) {
			const result: JsonValue[] = [];
			for (let index = 0; index < value.length; index += 1) {
				if (!Object.hasOwn(value, index)) throw new TypeError("Eval input arrays must not be sparse.");
				result.push(canonicalizeJson(value[index], ancestors));
			}
			return result;
		}
		const prototype = Object.getPrototypeOf(value);
		if (prototype !== Object.prototype && prototype !== null) {
			throw new TypeError("Eval input must contain only plain objects and arrays.");
		}
		const entries: Array<[string, unknown]> = Object.entries(value);
		return Object.fromEntries(
			entries
				.sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
				.map(([key, item]): [string, JsonValue] => [key, canonicalizeJson(item, ancestors)]),
		);
	} finally {
		ancestors.delete(value);
	}
}

View on GitHub (pinned to 4af9d21d3b)