{"record":{"id":"55ad0a27d1dd5234","repo":"koala73/worldmonitor","slug":"dataset-must-be-reported-occurrence-or-annual-aggr","errorCode":null,"errorMessage":"dataset must be reported_occurrence or annual_aggregate","messagePattern":"dataset must be reported_occurrence or annual_aggregate","errorType":"http","errorClass":"ApiError","httpStatus":400,"severity":"error","filePath":"server/worldmonitor/safety/v1/get-toronto-safety.ts","lineNumber":96,"sourceCode":"  return {\n    id: text(row.id),\n    objectId: numberOrZero(row.objectId),\n    eventYear: numberOrZero(row.eventYear),\n    divisionOriginal: text(row.divisionOriginal),\n    divisionFinal: text(row.divisionFinal),\n    neighbourhood: text(row.neighbourhood158),\n    eventCount: numberOrZero(row.eventCount),\n    incidentPoint: false,\n  };\n}\n\nexport async function queryTorontoSafety(\n  request: GetTorontoSafetyRequest,\n  readCache: CacheReader = readCachedJson,\n): Promise<GetTorontoSafetyResponse> {\n  const semantic = request.dataset || TORONTO_SAFETY_SEMANTICS.reportedOccurrence;\n  if (!VALID_DATASETS.has(semantic)) {\n    throw new ApiError(400, 'dataset must be reported_occurrence or annual_aggregate', '');\n  }\n\n  const sourceId = semantic === TORONTO_SAFETY_SEMANTICS.reportedOccurrence ? 'tps-mci' : 'tps-calls-attended';\n  const descriptor = torontoSafetySourceById(sourceId);\n  if (!descriptor || descriptor.productionWriter !== 'on-demand') throw new Error(`missing Toronto safety source: ${sourceId}`);\n\n  const [snapshotRead, metaRead] = await Promise.all([\n    readCache(descriptor.canonicalKey, true),\n    readCache(descriptor.seedMetaKey, true),\n  ]);\n  const snapshot = snapshotRead.status === 'hit' ? snapshotRead.value as TpsSnapshot : null;\n  const meta = metaRead.status === 'hit' ? metaRead.value as TpsMeta : null;\n  const validSnapshot = snapshot?.semantic === semantic\n    && snapshot.source === sourceId\n    && Array.isArray(snapshot.records);\n  const records = validSnapshot ? snapshot.records! : [];\n  const division = request.division || '';\n  const neighbourhood = request.neighbourhood || '';","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/koala73/worldmonitor/blob/eeab0a219fce0f02a00603b532dbae9041b934ac/server/worldmonitor/safety/v1/get-toronto-safety.ts#L78-L114","documentation":"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.","triggerScenarios":"Thrown at server/worldmonitor/safety/v1/get-toronto-safety.ts:96 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Send 'reported_occurrence' or 'annual_aggregate' (or omit dataset to use the default)","Restrict the dataset selector in the client to the two valid values"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"eeab0a219fce0f02a00603b532dbae9041b934ac","analyzedAt":"2026-08-21T16:51:25.751Z","contentChangedAt":"2026-08-21T16:51:25.751Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}