{"record":{"id":"2a2621b061b4202c","repo":"koala73/worldmonitor","slug":"writeaccuracysection-requires-the-canonical-datacatalog","errorCode":null,"errorMessage":"writeAccuracySection requires the canonical DataCatalog identity so the scorecard Dataset joins the catalog graph","messagePattern":"writeAccuracySection requires the canonical DataCatalog identity so the scorecard Dataset joins the catalog graph","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/build-accuracy-page.mjs","lineNumber":732,"sourceCode":"    confidenceIntervals: { published: false, trackedIn: CONFIDENCE_INTERVAL_ISSUE },\n    horizonProjections: { scored: false, trackedIn: HORIZON_SCORING_ISSUE },\n    scorecard: state.scorecard,\n  };\n  return `${JSON.stringify(payload, null, 2)}\\n`;\n}\n\nexport function writeAccuracySection({\n  outDir,\n  baseUrl,\n  tpl,\n  section,\n  lastmod = ACCURACY_CONTENT_VERSION,\n  dataset,\n  dataCatalog,\n  snapshotPath,\n}) {\n  if (!dataCatalog?.['@id'] || !dataset?.catalog?.['@id']) {\n    throw new Error(\n      'writeAccuracySection requires the canonical DataCatalog identity so the scorecard Dataset joins the catalog graph',\n    );\n  }\n  const state = classifyAccuracyState(section);\n  mkdirSync(join(outDir, 'accuracy'), { recursive: true });\n  writeFileSync(\n    join(outDir, 'accuracy', 'index.html'),\n    renderAccuracyPage({ baseUrl, tpl, state, lastmod, dataset, dataCatalog, snapshotPath }),\n  );\n  const downloadPath = join(outDir, dataset.file);\n  mkdirSync(dirname(downloadPath), { recursive: true });\n  writeFileSync(downloadPath, accuracyDatasetDownload({ state, snapshotPath }));\n  return { state };\n}\n","sourceCodeStart":714,"sourceCodeEnd":747,"githubUrl":"https://github.com/koala73/worldmonitor/blob/7d06c8633d256c18e38133030bc3613976a96ec9/scripts/build-accuracy-page.mjs#L714-L747","documentation":"writeAccuracySection builds the /accuracy/ page and its JSON-LD structured data. It requires both the DataCatalog node and the dataset's catalog reference to carry canonical '@id' values so the scorecard Dataset entity links into the catalog's knowledge graph. When either identity is missing the function throws instead of emitting broken/invalid structured data.","triggerScenarios":"Calling writeAccuracySection (or the build script) with dataCatalog undefined/null or without '@id', or with dataset.catalog missing its '@id' field.","commonSituations":"Adding a new dataset entry without wiring it into the DataCatalog registry; refactoring the JSON-LD builders and dropping the '@id' field; passing a partial catalog object in a test harness.","solutions":["Ensure the dataCatalog object passed in includes a canonical '@id' URL.","Ensure each dataset has dataset.catalog['@id'] pointing at the catalog's canonical identity.","Check where datasets are constructed/loaded and add the catalog linkage for any newly added dataset.","Add a pre-flight check on the dataset config so missing identities fail with a clearer message."],"exampleFix":"// before\nwriteAccuracySection({ dataset: { name: 'conflicts' }, snapshotPath });\n// after\nwriteAccuracySection({\n  dataset: { name: 'conflicts', catalog: { '@id': 'https://worldmonitor.app/#datacatalog' } },\n  dataCatalog: { '@id': 'https://worldmonitor.app/#datacatalog' },\n  snapshotPath,\n});","handlingStrategy":"validation","validationCode":"for (const d of datasets) {\n  if (!dataCatalog?.['@id']) throw new Error('dataCatalog missing @id');\n  if (!d.catalog?.['@id']) throw new Error(`dataset ${d.name} missing catalog @id`);\n}","typeGuard":"const hasCatalogIdentity = (d) => typeof d?.catalog?.['@id'] === 'string' && d.catalog['@id'].length > 0;","tryCatchPattern":"try {\n  writeAccuracySection({ dataset, dataCatalog, snapshotPath });\n} catch (e) {\n  if (String(e.message).includes('canonical DataCatalog identity')) {\n    console.error('Wire dataset/catalog @id before building /accuracy/:', e.message);\n  } else throw e;\n}","preventionTips":["Centralize catalog '@id' construction in one helper and reuse it for every dataset.","Validate the whole dataset registry (catalog linkage included) before any page build step.","Add a schema/type for dataset entries that makes catalog['@id'] required."],"tags":["seo","json-ld","build-time","structured-data"],"backgroundTag":"missing-required-argument","analyzedSha":"7d06c8633d256c18e38133030bc3613976a96ec9","analyzedAt":"2026-09-15T16:44:39.439Z","contentChangedAt":"2026-09-15T16:44:39.439Z","schemaVersion":2},"datasetVersion":"2026-09-15T18:17:12.389Z"}