koala73/worldmonitor · error · Error

${field} exceeds ${maxBytes} bytes

Error message

${field} exceeds ${maxBytes} bytes

What it means

Contract validation error from assertPlainText: the named field's UTF-8 encoding (after normalization and whitespace collapsing) exceeds the per-field byte limit (e.g. maxAliasBytes, maxIdentifierBytes). UTF-8 byte length matters: multibyte characters count more than ASCII.

Source

Thrown at shared/company-monitoring-contract.ts:85

  event: 'cm_event_',
  impact: 'cm_impact_',
  evidence: 'cm_evidence_',
} as const;
const ULID = '[0-9A-HJKMNP-TV-Z]{26}';

const encoder = new TextEncoder();

function utf8Bytes(value: string): number {
  return encoder.encode(value).byteLength;
}

function assertPlainText(value: unknown, field: string, maxBytes: number): string {
  if (typeof value !== 'string') throw new Error(`${field} must be a string`);
  const unicodeNormalized = value.normalize('NFC');
  if (CONTROL_CHARACTERS.test(unicodeNormalized)) throw new Error(`${field} contains control characters`);
  const normalized = unicodeNormalized.trim().replace(/\s+/g, ' ');
  if (!normalized) throw new Error(`${field} is required`);
  if (utf8Bytes(normalized) > maxBytes) throw new Error(`${field} exceeds ${maxBytes} bytes`);
  return normalized;
}

function normalizeOptionalText(value: unknown, field: string, maxBytes: number): string | undefined {
  if (value === undefined || value === null || value === '') return undefined;
  return assertPlainText(value, field, maxBytes);
}

function normalizeList(
  value: unknown,
  field: string,
  maxItems: number,
  normalize: (item: unknown, index: number) => string,
): string[] {
  if (value === undefined || value === null) return [];
  if (!Array.isArray(value)) throw new Error(`${field} must be a list`);
  if (value.length > maxItems) throw new Error(`${field} exceeds ${maxItems} items`);
  return [...new Set(value.map(normalize))].sort();

View on GitHub (pinned to eeab0a219f)

Solutions

  1. Shorten the field value to fit the documented byte limit
  2. Remember non-ASCII characters consume multiple bytes; trim accordingly
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at shared/company-monitoring-contract.ts:85 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of koala73/worldmonitor@eeab0a219f (2026-08-21). Data as JSON: /api/errors/a46de383ffa66ac8. Report an issue: GitHub.