diegosouzapw/OmniRoute · error · ClaudeWebProtocolError

must be an object

Error message

${context} must be an object

What it means

Generic shape guard requireRecord: a field expected to be a JSON object (e.g. message, content_block, or delta inside a Claude Web protocol event) is null, a non-object, or an array. The context string in the interpolated message names which field failed; the event came from upstream but does not match the expected protocol schema.

Solutions

  1. Inspect the context name in the thrown message to identify the malformed field and log the raw event for diagnosis
  2. Treat as an upstream protocol change: end the stream cleanly rather than partially emitting
  3. If claude.ai changed its event schema, update parseProtocolEvent/field expectations in stream.ts
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at open-sse/executors/claude-web/stream.ts:174 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/81d5ecde281be254. Report an issue: GitHub.

Appendix: source

Thrown at open-sse/executors/claude-web/stream.ts:174

  }
  return undefined;
}

function projectMetadataEvent(
  eventType: string,
  event: Record<string, unknown>
): Record<string, unknown> {
  const projected: Record<string, unknown> = { type: eventType };
  for (const field of METADATA_EVENT_FIELDS[eventType] ?? []) {
    const value = safeMetadataValue(event[field]);
    if (value !== undefined) projected[field] = value;
  }
  return projected;
}

function requireRecord(value: unknown, context: string): Record<string, unknown> {
  if (!value || typeof value !== "object" || Array.isArray(value)) {
    throw new ClaudeWebProtocolError(`${context} must be an object`);
  }
  return value as Record<string, unknown>;
}

function requireBlockIndex(event: Record<string, unknown>): number {
  if (!Number.isInteger(event.index) || (event.index as number) < 0) {
    throw new ClaudeWebProtocolError("Content block index is invalid");
  }
  return event.index as number;
}

function deltaText(delta: Record<string, unknown>, fields: string[]): string {
  for (const field of fields) {
    const value = delta[field];
    if (typeof value === "string") return value;
  }
  throw new ClaudeWebProtocolError("Content delta text is invalid");
}

View on GitHub (pinned to a179ffed5b)