koala73/worldmonitor · error · ApiError

dataset must be reported_occurrence or annual_aggregate

Error message

dataset must be reported_occurrence or annual_aggregate

What it means

Request validation in queryTorontoSafety: req.dataset is neither 'reported_occurrence' nor 'annual_aggregate' (the VALID_DATASETS set); when omitted a default is applied, so reaching this throw means an explicitly invalid dataset value was sent.

Source

Thrown at server/worldmonitor/safety/v1/get-toronto-safety.ts:96

  return {
    id: text(row.id),
    objectId: numberOrZero(row.objectId),
    eventYear: numberOrZero(row.eventYear),
    divisionOriginal: text(row.divisionOriginal),
    divisionFinal: text(row.divisionFinal),
    neighbourhood: text(row.neighbourhood158),
    eventCount: numberOrZero(row.eventCount),
    incidentPoint: false,
  };
}

export async function queryTorontoSafety(
  request: GetTorontoSafetyRequest,
  readCache: CacheReader = readCachedJson,
): Promise<GetTorontoSafetyResponse> {
  const semantic = request.dataset || TORONTO_SAFETY_SEMANTICS.reportedOccurrence;
  if (!VALID_DATASETS.has(semantic)) {
    throw new ApiError(400, 'dataset must be reported_occurrence or annual_aggregate', '');
  }

  const sourceId = semantic === TORONTO_SAFETY_SEMANTICS.reportedOccurrence ? 'tps-mci' : 'tps-calls-attended';
  const descriptor = torontoSafetySourceById(sourceId);
  if (!descriptor || descriptor.productionWriter !== 'on-demand') throw new Error(`missing Toronto safety source: ${sourceId}`);

  const [snapshotRead, metaRead] = await Promise.all([
    readCache(descriptor.canonicalKey, true),
    readCache(descriptor.seedMetaKey, true),
  ]);
  const snapshot = snapshotRead.status === 'hit' ? snapshotRead.value as TpsSnapshot : null;
  const meta = metaRead.status === 'hit' ? metaRead.value as TpsMeta : null;
  const validSnapshot = snapshot?.semantic === semantic
    && snapshot.source === sourceId
    && Array.isArray(snapshot.records);
  const records = validSnapshot ? snapshot.records! : [];
  const division = request.division || '';
  const neighbourhood = request.neighbourhood || '';

View on GitHub (pinned to eeab0a219f)

Solutions

  1. Send 'reported_occurrence' or 'annual_aggregate' (or omit dataset to use the default)
  2. Restrict the dataset selector in the client to the two valid values
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at server/worldmonitor/safety/v1/get-toronto-safety.ts:96 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/55ad0a27d1dd5234. Report an issue: GitHub.