santifer/career-ops · error · Error

changedSections must be an array

Error message

changedSections must be an array

What it means

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.).

Solutions

  1. Pass changedSections as an array, even when empty: changedSections: [].
  2. Wrap a single value: changedSections: ['summary'] or changedSections: raw == null ? [] : [raw].
  3. Split comma-separated input before calling: raw.split(',').map(s => s.trim()).filter(Boolean).
  4. If the value may come from JSON where empty arrays became null, coerce with Array.isArray(x) ? x : [] at the boundary.

Example fix

// before
await writeReuseDecision({ paths, decision: 'partial', score: 3.5, changedSections: null });
// after
await writeReuseDecision({ paths, decision: 'partial', score: 3.5, changedSections: sections ?? [] });
Defensive patterns

Strategy: type-guard

Validate before calling

if (!Array.isArray(changedSections)) {
  throw new Error(`changedSections must be an array, got ${typeof changedSections}`);
}

Type guard

const isStringArray = (v) => Array.isArray(v) && v.every((x) => typeof x === 'string');

Try / catch

try {
  await writeReuseDecision({ paths, decision, score, changedSections });
} catch (err) {
  if (err.message.includes('changedSections must be an array')) {
    await writeReuseDecision({ paths, decision, score, changedSections: [] });
  } else throw err;
}

Prevention

When it happens

Trigger: 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 [].

Common situations: 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.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of santifer/career-ops@aac998c7ed (2026-09-16). Data as JSON: /api/errors/598a07e5b0c7d82f. Report an issue: GitHub.

Appendix: source

Thrown at application-artifacts.mjs:88

    join(paths.root, 'cv', 'source'),
    paths.cv.tailored.root,
    join(paths.root, 'decision'),
  ]) mkdirSync(directory, { recursive: true });
  return paths;
}

/** Write an auditable CV reuse decision beside the application artifacts. */
export function writeReuseDecision(paths, {
  decision,
  score = null,
  sourceCv = null,
  currentJd = null,
  previousSource = null,
  changedSections = [],
  userOverride = false,
}) {
  if (!DECISIONS.has(decision)) throw new Error(`decision must be one of: ${[...DECISIONS].join(', ')}`);
  if (!Array.isArray(changedSections)) throw new Error('changedSections must be an array');
  ensureApplicationArtifactDirs(paths);
  const record = {
    schema_version: 1,
    decision,
    score,
    source_cv: sourceCv,
    current_jd: currentJd,
    previous_source: previousSource,
    changed_sections: changedSections,
    user_override: Boolean(userOverride),
    recorded_at: new Date().toISOString(),
  };
  writeFileSync(paths.decision.reuse, `${JSON.stringify(record, null, 2)}\n`);
  return record;
}

// --help was swallowed by parseArgs's strict mode and reported as an unknown
// option (#2774), so the built-in help flag looked like a typo. Handled via

View on GitHub (pinned to aac998c7ed)