{"record":{"id":"598a07e5b0c7d82f","repo":"santifer/career-ops","slug":"changedsections-must-be-an-array","errorCode":null,"errorMessage":"changedSections must be an array","messagePattern":"changedSections must be an array","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"application-artifacts.mjs","lineNumber":88,"sourceCode":"    join(paths.root, 'cv', 'source'),\n    paths.cv.tailored.root,\n    join(paths.root, 'decision'),\n  ]) mkdirSync(directory, { recursive: true });\n  return paths;\n}\n\n/** Write an auditable CV reuse decision beside the application artifacts. */\nexport function writeReuseDecision(paths, {\n  decision,\n  score = null,\n  sourceCv = null,\n  currentJd = null,\n  previousSource = null,\n  changedSections = [],\n  userOverride = false,\n}) {\n  if (!DECISIONS.has(decision)) throw new Error(`decision must be one of: ${[...DECISIONS].join(', ')}`);\n  if (!Array.isArray(changedSections)) throw new Error('changedSections must be an array');\n  ensureApplicationArtifactDirs(paths);\n  const record = {\n    schema_version: 1,\n    decision,\n    score,\n    source_cv: sourceCv,\n    current_jd: currentJd,\n    previous_source: previousSource,\n    changed_sections: changedSections,\n    user_override: Boolean(userOverride),\n    recorded_at: new Date().toISOString(),\n  };\n  writeFileSync(paths.decision.reuse, `${JSON.stringify(record, null, 2)}\\n`);\n  return record;\n}\n\n// --help was swallowed by parseArgs's strict mode and reported as an unknown\n// option (#2774), so the built-in help flag looked like a typo. Handled via","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/application-artifacts.mjs#L70-L106","documentation":"writeReuseDecision requires changedSections to be an array because it is stored in the record and later consumed as a list. It throws this error when the argument is not an array (string, null, object, missing-but-explicitly-passed, etc.).","triggerScenarios":"Calling writeReuseDecision({ ..., changedSections: 'summary' }) (a single section passed as a string), changedSections: null, passing an object/Map/Set instead of an array, or a caller that defaults the field to null rather than [].","commonSituations":"A wrapper function forwards user input where a single item was provided without wrapping in an array; JSON round-tripping turns an empty array into null; TypeScript-less code refactors a param from array to scalar at one call site but not the validator; spreading a comma-separated CLI flag string instead of splitting it.","solutions":["Pass changedSections as an array, even when empty: changedSections: [].","Wrap a single value: changedSections: ['summary'] or changedSections: raw == null ? [] : [raw].","Split comma-separated input before calling: raw.split(',').map(s => s.trim()).filter(Boolean).","If the value may come from JSON where empty arrays became null, coerce with Array.isArray(x) ? x : [] at the boundary."],"exampleFix":"// before\nawait writeReuseDecision({ paths, decision: 'partial', score: 3.5, changedSections: null });\n// after\nawait writeReuseDecision({ paths, decision: 'partial', score: 3.5, changedSections: sections ?? [] });","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(changedSections)) {\n  throw new Error(`changedSections must be an array, got ${typeof changedSections}`);\n}","typeGuard":"const isStringArray = (v) => Array.isArray(v) && v.every((x) => typeof x === 'string');","tryCatchPattern":"try {\n  await writeReuseDecision({ paths, decision, score, changedSections });\n} catch (err) {\n  if (err.message.includes('changedSections must be an array')) {\n    await writeReuseDecision({ paths, decision, score, changedSections: [] });\n  } else throw err;\n}","preventionTips":["Default to [] (as the function signature does), never null.","Wrap single section names in an array at the call site.","Coerce at the JSON boundary: Array.isArray(x) ? x : [].","Avoid spreading comma-separated strings — split them into a real array."],"tags":["validation","type-mismatch","arguments"],"backgroundTag":"type-mismatch","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}