diegosouzapw/OmniRoute · error · Error
Invalid cookie JSON at index
Error message
Invalid cookie JSON at index ${i}: expected an object What it means
Validation guard in parseJsonCookiesToHeader(): the stored cookie JSON parsed as an array, but the element at the given index is not a plain object (it is null, a primitive, or a nested array). Only that element is at fault; the input must be an array of {name, value} cookie objects.
Solutions
- Fix the stored cookie JSON so every array element is an object like {"name":"session","value":"..."}.
- Replace the malformed element with a valid cookie entry or remove it from the array.
- If the intent was a raw cookie header string (name=value; ...), store it without the surrounding [ ... ] so the JSON path is skipped.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/lib/providers/webCookieAuth.ts:46 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25).
Data as JSON: /api/errors/d48096c62ab3efa2.
Report an issue: GitHub.
Appendix: source
Thrown at src/lib/providers/webCookieAuth.ts:46
export function parseJsonCookiesToHeader(rawValue: string): string | null {
const trimmed = (rawValue || "").trim();
if (!trimmed || !trimmed.startsWith("[")) return null;
let parsed: unknown;
try {
parsed = JSON.parse(trimmed);
} catch {
return null;
}
if (!Array.isArray(parsed)) return null;
if (parsed.length === 0) return "";
const parts: string[] = [];
for (let i = 0; i < parsed.length; i++) {
const entry = parsed[i];
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
throw new Error(`Invalid cookie JSON at index ${i}: expected an object`);
}
const record = entry as Record<string, unknown>;
if (typeof record.name !== "string" || !record.name) {
throw new Error(`Invalid cookie JSON at index ${i}: missing required field 'name'`);
}
if (typeof record.value !== "string") {
throw new Error(`Invalid cookie JSON at index ${i}: missing required field 'value'`);
}
parts.push(`${record.name}=${record.value}`);
}
return parts.join("; ");
}
export function normalizeSessionCookieHeader(rawValue: string, defaultCookieName: string): string {
const stripped = stripCookieInputPrefix(rawValue);View on GitHub (pinned to a179ffed5b)