{"record":{"id":"ec7567adc2e4d282","repo":"santifer/career-ops","slug":"key-must-be-an-array-in-path","errorCode":null,"errorMessage":"${key} must be an array in ${path}","messagePattern":"(.+?) must be an array in (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"verify-cv-facts.mjs","lineNumber":804,"sourceCode":" * file loaded the phrase check cannot fail — and a gate that is DISABLED then\n * reads exactly like a gate that RAN AND FOUND NOTHING. `missing` is the one bit\n * that tells them apart; callers surface it (#3894).\n *\n * Nothing here turns a missing config into an error. A user who has never\n * written a cv-facts.json is in a normal state; they just should not be left\n * believing a gate is protecting them when none is loaded.\n *\n * @param {string} path absolute path to the configuration file\n * @returns {{missing: boolean, config: {allow_metrics: string[], allow_facts: string[], forbidden_phrases: string[], warn_phrases: string[]}}}\n * @throws when the file exists but is unparseable or has a non-array key\n */\nexport function loadFactConfig(path) {\n  const keys = ['allow_metrics', 'allow_facts', 'forbidden_phrases', 'warn_phrases'];\n  if (!existsSync(path)) return { missing: true, config: Object.fromEntries(keys.map(key => [key, []])) };\n  const config = JSON.parse(readFileSync(path, 'utf-8'));\n  for (const key of keys) {\n    if (config[key] == null) config[key] = [];\n    else if (!Array.isArray(config[key])) throw new Error(`${key} must be an array in ${path}`);\n  }\n  return { missing: false, config };\n}\n\n/** Resolve a CLI or configuration path relative to the selected working directory. */\nfunction resolveInputPath(path, cwd = process.cwd()) {\n  return isAbsolute(path) ? path : join(cwd, path);\n}\n\n/** Check a normalized fact as a complete token or phrase, not a substring. */\nfunction sourceContainsFact(sourceText, value) {\n  const escaped = value\n    .replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n    .replace(/\\s+/g, '\\\\s+');\n  return new RegExp(`(?:^|[^\\\\p{L}\\\\p{N}+#/-])${escaped}(?=$|[^\\\\p{L}\\\\p{N}+#/-])`, 'iu').test(sourceText);\n}\n\n/**","sourceCodeStart":786,"sourceCodeEnd":822,"githubUrl":"https://github.com/santifer/career-ops/blob/e7abd431fce9348a95261acac9e0c14779c35df8/verify-cv-facts.mjs#L786-L822","documentation":"loadFactConfig() in verify-cv-facts.mjs validates the fact-checker's JSON config: each of allow_metrics, allow_facts, forbidden_phrases, warn_phrases must be an array. If the key is present, non-null, and not an array, it throws '${key} must be an array in ${path}'.","triggerScenarios":"A cv-facts config JSON where a list key is a string (\"forbidden_phrases\": \"foo, bar\"), an object, or a number instead of a JSON array. Also hit when a hand-edited config swaps an array for a single value.","commonSituations":"Hand-editing the config and writing comma-separated strings instead of arrays; YAML-style unquoted list syntax saved into a .json file; tool migration writing object maps instead of arrays.","solutions":["Open the config file named in the error and make the offending key a JSON array","Convert a comma-separated string into an array of strings: [\"foo\", \"bar\"]","Validate the JSON: node -e \"JSON.parse(require('fs').readFileSync('<path>','utf8'))\" and inspect the key's type","If the key is optional, either remove it or set it to []"],"exampleFix":"// before (config.json)\n{ \"forbidden_phrases\": \" fabricated, invented \" }\n// after\n{ \"forbidden_phrases\": [\"fabricated\", \"invented\"] }","handlingStrategy":"validation","validationCode":"const cfg = JSON.parse(readFileSync(path, 'utf-8'));\nfor (const key of ['allow_metrics','allow_facts','forbidden_phrases','warn_phrases']) {\n  if (cfg[key] != null && !Array.isArray(cfg[key])) {\n    throw new Error(`${key} must be an array in ${path} (got ${typeof cfg[key]})`);\n  }\n}","typeGuard":"const isArrayKey = (cfg, key) => cfg[key] == null || Array.isArray(cfg[key]);","tryCatchPattern":"try {\n  const { config } = loadFactConfig(configPath);\n} catch (err) {\n  if (err.message.includes('must be an array')) {\n    console.error(`Fix config: ${err.message}`);\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Write config list values as JSON arrays of strings, never comma-separated strings","Lint/JSON-schema-validate the config file before use","Keep config edits in one place and re-validate after every change","If migrating from YAML, convert unquoted list syntax explicitly to JSON arrays"],"tags":["config","validation","json"],"backgroundTag":"config-type-mismatch","analyzedSha":"e7abd431fce9348a95261acac9e0c14779c35df8","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}