{"record":{"id":"30ec0427f5b3a927","repo":"santifer/career-ops","slug":"malformed-benchmarks-file-at-path-expected-a-t","errorCode":null,"errorMessage":"Malformed benchmarks file at ${path}: expected a top-level \"benchmarks\" map","messagePattern":"Malformed benchmarks file at (.+?): expected a top-level \"benchmarks\" map","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"funnel-velocity.mjs","lineNumber":231,"sourceCode":"      sameDayExcluded,\n      censored,\n    };\n  }\n  return result;\n}\n\n// --- Benchmarks ---\nexport function loadBenchmarks(explicitPath) {\n  const path = explicitPath\n    || (existsSync(join(CAREER_OPS, 'config/benchmarks.yml')) ? join(CAREER_OPS, 'config/benchmarks.yml') : join(CAREER_OPS, 'templates/benchmarks.yml'));\n  let doc;\n  try {\n    doc = yaml.load(readFileSync(path, 'utf-8'));\n  } catch (err) {\n    throw new Error(`Cannot read benchmarks at ${path}: ${err.message}`);\n  }\n  if (!doc || typeof doc.benchmarks !== 'object' || doc.benchmarks === null) {\n    throw new Error(`Malformed benchmarks file at ${path}: expected a top-level \"benchmarks\" map`);\n  }\n  return { benchmarks: doc.benchmarks, path };\n}\n\n/** Classify an own-rate percentage against a benchmark's range (inclusive). */\nexport function classify(ownPct, metric) {\n  if (ownPct === null || ownPct === undefined || !metric || !Array.isArray(metric.range_pct)) return null;\n  const [lo, hi] = metric.range_pct;\n  const band = ownPct < lo ? 'below-range' : ownPct > hi ? 'above-range' : 'within-range';\n  const typical = metric.typical_pct;\n  return {\n    band,\n    ownPct,\n    rangePct: [lo, hi],\n    typicalPct: typical ?? null,\n    vsTypical: typical ? Math.round((ownPct / typical) * 10) / 10 : null,\n    source: metric.source ?? null,\n    year: metric.year ?? null,","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/santifer/career-ops/blob/9b17a8ac97b398a496b38e423ae24e433b43254f/funnel-velocity.mjs#L213-L249","documentation":"The benchmarks YAML loaded successfully but the top-level structure is wrong: doc.benchmarks must be a non-null object (a map of metric keys like response_rate, application_to_interview). This fires when benchmarks is missing, is an array, is a string, or is explicitly null.","triggerScenarios":"The YAML has a top-level array instead of a map; the key is misspelled (benchmark: instead of benchmarks:); benchmarks: is present but empty/null; indentation nests benchmarks under another key so it is not top-level.","commonSituations":"User hand-edits config/benchmarks.yml and renames or restructures the key; a YAML indentation error pushes benchmarks under a parent key; the file was replaced with a flat list.","solutions":["Ensure the YAML has a top-level benchmarks: key mapping to an object, e.g. benchmarks:\\n  response_rate:\\n    range_pct: [2, 13].","Compare against templates/benchmarks.yml for the expected structure.","Validate with node -e \"const d=require('js-yaml').load(require('fs').readFileSync('config/benchmarks.yml','utf-8')); console.log(typeof d.benchmarks, d.benchmarks)\"."],"exampleFix":"# before (malformed)\nbenchmarks:\n  - response_rate\n  - application_to_interview\n\n# after\nbenchmarks:\n  response_rate:\n    range_pct: [2, 13]\n    typical_pct: 3\n    year: 2025\n  application_to_interview:\n    range_pct: [3, 15]\n    typical_pct: 5\n    year: 2025","handlingStrategy":"validation","validationCode":"import * as yaml from 'js-yaml';\nimport { readFileSync } from 'fs';\n\nfunction validateBenchmarksShape(path) {\n  const doc = yaml.load(readFileSync(path, 'utf-8'));\n  if (!doc || typeof doc.benchmarks !== 'object' || doc.benchmarks === null) {\n    throw new Error(`Expected top-level \"benchmarks\" object map in ${path}`);\n  }\n  return doc.benchmarks;\n}","typeGuard":"/** @param {unknown} doc */\nfunction isBenchmarksDoc(doc) {\n  return (\n    typeof doc === 'object' && doc !== null &&\n    'benchmarks' in doc &&\n    typeof doc.benchmarks === 'object' &&\n    doc.benchmarks !== null &&\n    !Array.isArray(doc.benchmarks)\n  );\n}","tryCatchPattern":null,"preventionTips":["Always use a top-level benchmarks: key mapping to an object, not an array or list.","Compare custom config/benchmarks.yml against templates/benchmarks.yml for structure.","Run the module's --self-test to catch structural regressions."],"tags":["config","yaml","validation","benchmarks"],"backgroundTag":null,"analyzedSha":"9b17a8ac97b398a496b38e423ae24e433b43254f","analyzedAt":"2026-08-13T00:48:39.135Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}