{"record":{"id":"40c8b165f2249035","repo":"chenglou/pretext","slug":"corpus-page-returned-error-for-meta-id-varia","errorCode":null,"errorMessage":"Corpus page returned error for ${meta.id} (${variant.id}): ${report.message ?? 'unknown error'}","messagePattern":"Corpus page returned error for (.+?) \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/corpus-font-matrix.ts","lineNumber":484,"sourceCode":"      `&lineHeight=${variant.lineHeight}` +\n      `&reportEndpoint=${encodeURIComponent(reportServer.endpoint)}`\n\n    const report = await (async () => {\n      try {\n        return await loadPostedReport(\n          session,\n          url,\n          () => reportServer.waitForReport(null),\n          requestId,\n          options.browser,\n          options.timeoutMs,\n        )\n      } finally {\n        reportServer.close()\n      }\n    })()\n    if (report.status === 'error') {\n      throw new Error(`Corpus page returned error for ${meta.id} (${variant.id}): ${report.message ?? 'unknown error'}`)\n    }\n    if (report.rows === undefined) {\n      throw new Error(`Corpus font matrix report was missing rows for ${meta.id} (${variant.id})`)\n    }\n\n    const mismatches: VariantResult['mismatches'] = report.rows\n      .filter(row => Math.round(row.diffPx) !== 0)\n      .map(row => ({\n        width: row.width,\n        diffPx: Math.round(row.diffPx),\n        predictedHeight: Math.round(row.predictedHeight),\n        actualHeight: Math.round(row.actualHeight),\n      }))\n    const exactCount = report.exactCount ?? (report.rows.length - mismatches.length)\n\n    variantResults.push({\n      id: variant.id,\n      label: variant.label,","sourceCodeStart":466,"sourceCodeEnd":502,"githubUrl":"https://github.com/chenglou/pretext/blob/ac49b09b7d83ede19581fa94a8b892b07d309baf/scripts/corpus-font-matrix.ts#L466-L502","documentation":"Thrown inside the per-variant sweep loop of corpus-font-matrix.ts after a POSTed report arrives with `status: 'error'`. The page-side harness ran, surfaced a structured error (report.message, else 'unknown error'), and the host rethrows it attributed to the corpus and font variant. This is the page explicitly saying \"I could not measure this corpus under this font\" — distinct from a timeout ([24]) where the page never answered.","triggerScenarios":"loadPostedReport resolves with a report object whose `status === 'error'`. The page sets this when: the corpus text failed to load or prepare; the requested font string is invalid or unavailable on the system so canvas measurement fell back badly; a DOM element the page expects (the measure target) was missing; an exception was caught inside the page's measurement loop and reported via the POST channel rather than crashing silently.","commonSituations":"Font string references a family not installed on the machine (the corpus runs locally, so a missing CJK font is the classic cause); corpus text path changed and the page's loader returned empty; a browser/OS difference (e.g., Safari missing a font Chrome has) makes one variant error while others succeed; the page's error reporter caught a downstream TypeError and forwarded only a generic message.","solutions":["Read report.message in the error text — the page intentionally surfaces a cause string, and 'unknown error' means the page caught something it did not classify.","Verify the variant's font string is resolvable on this OS/browsers: open the corpus page in a headed run of the same browser and check the applied font in devtools.","For CJK corpora, confirm the required font families (Hiragino Mincho ProN, Yu Mincho, Noto Serif CJK JP, etc.) are installed — macOS vs Linux font sets differ sharply.","Cross-check the same corpus under the default variant to isolate whether the error is corpus-specific or font-specific.","If the message is generic, add richer error context in the page-side measurement code so future failures self-explain."],"exampleFix":"// before\nif (report.status === 'error') {\n  throw new Error(`Corpus page returned error for ${meta.id} (${variant.id}): ${report.message ?? 'unknown error'}`)\n}\n// after — attribute the font so the cause is obvious without re-reading variant config\nif (report.status === 'error') {\n  throw new Error(`Corpus page error for ${meta.id} (${variant.id}, font=${variant.font}): ${report.message ?? 'unknown error'}`)\n}","handlingStrategy":"try-catch","validationCode":"// Pre-flight that the variant's font is resolvable before sweeping\nasync function canResolveFont(font: string): Promise<boolean> {\n  // crude: ensure the families referenced are not obviously absent on this OS\n  // (full check belongs in the headed browser, but this catches typos)\n  return /\\d+px\\s+/.test(font) // must start with a size; deeper checks need the browser\n}","typeGuard":"function isErrorReport(report: { status?: string }): report is { status: 'error'; message?: string } {\n  return report.status === 'error'\n}","tryCatchPattern":"try {\n  report = await loadPostedReport(session, url, () => reportServer.waitForReport(null), requestId, options.browser, options.timeoutMs)\n} catch (error) {\n  if (error instanceof Error && error.message.startsWith('Corpus page returned error')) {\n    // Page-reported error — isolate by re-running the same corpus under the default variant in a headed browser\n    console.error(`${error.message}. Reproduce headed: open ${url} in ${options.browser} and watch the console.`)\n  }\n  throw error\n}\nif (isErrorReport(report)) {\n  throw new Error(`Corpus page error for ${meta.id} (${variant.id}, font=${variant.font}): ${report.message ?? 'unknown error'}`)\n}","preventionTips":["Confirm the variant font families are installed on the host OS, especially CJK families for ja/zh corpora.","Reproduce the failing variant in a headed browser (open the same URL) — the page-side console has the real cause.","Cross-check the same corpus under the default variant to isolate font-specific vs corpus-specific failures.","Enrich the page's error reporter so report.message carries a concrete cause rather than 'unknown error'."],"tags":["browser-automation","report","page-error","corpus-font-matrix","font"],"backgroundTag":null,"analyzedSha":"ac49b09b7d83ede19581fa94a8b892b07d309baf","analyzedAt":"2026-08-12T17:03:16.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}