musistudio/claude-code-router · error · Error

Script result must be JSON serializable.

Error message

Script result must be JSON serializable.

What it means

Error "Script result must be JSON serializable." thrown in musistudio/claude-code-router.

Source

Thrown at packages/core/src/routing/route-script-worker.ts:311

  return path.resolve(file);
}

function assertHttpUrl(rawUrl: string): void {
  let url: URL;
  try {
    url = new URL(rawUrl);
  } catch {
    throw new Error(`Invalid URL "${rawUrl}".`);
  }
  if ((url.protocol !== "http:" && url.protocol !== "https:") || url.username || url.password || !url.hostname) {
    throw new Error("Only HTTP(S) URLs without embedded credentials are supported.");
  }
}

function serializeResult(value: unknown): unknown {
  if (value === undefined) return undefined;
  const encoded = JSON.stringify(value);
  if (encoded === undefined) throw new Error("Script result must be JSON serializable.");
  if (Buffer.byteLength(encoded, "utf8") > maxResultBytes) {
    throw new Error(`Script result exceeds ${maxResultBytes} bytes.`);
  }
  return JSON.parse(encoded);
}

async function withDeadline<T>(promise: Promise<T>, deadline: number): Promise<T> {
  const remainingMs = Math.max(1, deadline - Date.now());
  let timer: NodeJS.Timeout | undefined;
  try {
    return await Promise.race([
      promise,
      new Promise<T>((_resolve, reject) => {
        timer = setTimeout(() => reject(timeoutError()), remainingMs);
      })
    ]);
  } finally {
    if (timer) clearTimeout(timer);

View on GitHub (pinned to 99f24806c6)

When it happens

Trigger: Thrown at packages/core/src/routing/route-script-worker.ts:311 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of musistudio/claude-code-router@99f24806c6 (2026-08-27). Data as JSON: /api/errors/c2226c57e232863a. Report an issue: GitHub.