musistudio/claude-code-router · error · Error

${message}

Error message

${message}

What it means

A generic required-string validation error thrown by readRequiredString in the management server. The helper trims the incoming value and rejects anything that is not a non-empty string; the interpolated message names the specific field that failed (e.g. 'sessionId is required.'). It exists to fail fast when JSON-RPC/HTTP request payloads are missing mandatory string fields.

Source

Thrown at packages/core/src/web/management-server.ts:1518

      return "text/javascript; charset=utf-8";
    case ".jpg":
    case ".jpeg":
      return "image/jpeg";
    case ".png":
      return "image/png";
    case ".svg":
      return "image/svg+xml";
    case ".webp":
      return "image/webp";
    default:
      return "application/octet-stream";
  }
}

function readRequiredString(value: unknown, message: string): string {
  const text = readString(value);
  if (!text) {
    throw new Error(message);
  }
  return text;
}

function readString(value: unknown): string | undefined {
  return typeof value === "string" && value.trim() ? value.trim() : undefined;
}

function readEnvString(key: string): string | undefined {
  return readString(process.env[key]);
}

function readEnvPort(key: string): number | undefined {
  const value = Number(process.env[key]);
  return Number.isInteger(value) && value > 0 && value < 65536 ? value : undefined;
}

function pluginIdValue(value: string | undefined): string {

View on GitHub (pinned to 99f24806c6)

Solutions

  1. Check the error message text — it names the exact missing field; add that field as a non-empty trimmed string to your request payload.
  2. Ensure the field is serialized as a JSON string, not a number/boolean/object.
  3. Trim client-side input and reject empty values before sending the request.

Example fix

// before
await api.createSession({ sessionId: "", label: 42 });

// after
await api.createSession({ sessionId: "session-1", label: "42" });
Defensive patterns

Strategy: validation

Validate before calling

const payload = { sessionId: String(raw.sessionId ?? "").trim() };
if (!payload.sessionId) throw new Error("sessionId missing — fix the form before submitting");
await api.call(payload);

Type guard

function hasRequiredString<T extends string>(o: unknown, key: T): o is Record<T, string> { return typeof (o as any)?.[key] === "string" && (o as any)[key].trim().length > 0; }

Try / catch

try { await api.call(payload); } catch (e) { if (e instanceof Error && /is required\.$/.test(e.message)) { /* e.message names the missing field; fix payload */ } throw e; }

Prevention

When it happens

Trigger: Sending a request payload to a management server endpoint where a required string field is undefined, null, a non-string type, an empty string, or a whitespace-only string.

Common situations: A client omits an optional-looking field from the request body; a field is sent as a number or object instead of a string; trimmed whitespace (e.g. '" \t"') sneaks in from form input.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


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