{"record":{"id":"79421732be2e3a22","repo":"santifer/career-ops","slug":"cv-md-not-found-cannot-add-to-a-cv-that-does-not","errorCode":null,"errorMessage":"cv.md not found — cannot add to a CV that does not exist","messagePattern":"cv\\.md not found — cannot add to a CV that does not exist","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"add-entry.mjs","lineNumber":184,"sourceCode":" * contents and a per-target status. No I/O — this is what the tests exercise.\n * @returns {{ cv: string, articleDigest: string, result: object }}\n */\nexport function applyAdd(payload, { cvText = null, articleText = null } = {}) {\n  if (!payload || typeof payload !== 'object' || (!payload.cv && !payload.articleDigest)) {\n    throw new Error('payload must include at least one of: cv, articleDigest');\n  }\n\n  const result = {};\n  let cv = cvText;\n  let articleDigest = articleText;\n\n  if (payload.cv) {\n    const { section, dedupKey, entry } = payload.cv;\n    if (!section || !entry) throw new Error('payload.cv requires { section, entry }');\n    // dedupKey is what makes the insert idempotent — refuse to add without one\n    // rather than silently allowing duplicate re-runs.\n    if (!normalizeKey(dedupKey)) throw new Error('payload.cv requires a non-empty dedupKey (used for dedup/idempotency)');\n    if (cvText === null) throw new Error(`cv.md not found — cannot add to a CV that does not exist`);\n    if (cvHasEntry(cvText, section, dedupKey)) {\n      result.cv = { status: 'duplicate', section };\n    } else {\n      cv = insertIntoCvSection(cvText, section, entry);\n      result.cv = { status: 'added', section };\n    }\n  }\n\n  if (payload.articleDigest) {\n    const { dedupKey, entry } = payload.articleDigest;\n    if (!entry) throw new Error('payload.articleDigest requires { entry }');\n    if (!normalizeKey(dedupKey)) throw new Error('payload.articleDigest requires a non-empty dedupKey (used for dedup/idempotency)');\n    // article-digest.md is optional; create it from a header when missing.\n    const current = articleText === null\n      ? '# Article Digest -- Proof Points\\n\\nCompact proof points from portfolio projects. Read by career-ops at evaluation time.\\n'\n      : articleText;\n    if (articleDigestHasEntry(current, dedupKey)) {\n      result.articleDigest = { status: 'duplicate' };","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/add-entry.mjs#L166-L202","documentation":"applyAdd is pure: it operates on the current file contents passed in as cvText. When the caller passes cvText === null — the sentinel meaning cv.md does not exist or could not be read — it refuses to add CV content, because insertIntoCvSection cannot invent a CV. Note article-digest.md is created from a default header when missing, but cv.md deliberately is not.","triggerScenarios":"Calling applyAdd({ cv: {...} }) with the options argument omitted (defaults cvText to null), reading cv.md with a helper that returns null on ENOENT, or running the add flow in a directory where cv.md was never created (onboarding not completed).","commonSituations":"Fresh career-ops checkout before onboarding (doctor.mjs reports cv.md as missing), a typo'd path passed to the file reader, or a script that swallows the read error and forwards null.","solutions":["Create cv.md in the repo root first (paste your CV to the assistant, or write one from your LinkedIn/experience), then re-run the add.","Fix the file-reading call site so it returns the file's text — and surfaces read errors instead of null.","Run `node doctor.mjs --json` to confirm cv.md exists before invoking add flows."],"exampleFix":"// before\nconst cvText = fs.existsSync('cv.md') ? null : fs.readFileSync('cv.md', 'utf8'); // inverted\napplyAdd(payload, { cvText });\n\n// after\nconst cvText = fs.existsSync('cv.md') ? fs.readFileSync('cv.md', 'utf8') : null;\nif (cvText === null) throw new Error('cv.md missing — create it before adding entries');\napplyAdd(payload, { cvText });","handlingStrategy":"validation","validationCode":"const cvText = fs.existsSync(cvPath) ? fs.readFileSync(cvPath, 'utf8') : null;\nif (payload.cv && cvText === null) {\n  throw new Error('Refusing to add: cv.md does not exist yet — create it first');\n}","typeGuard":"null","tryCatchPattern":"try {\n  applyAdd(payload, { cvText });\n} catch (e) {\n  if (e.message.includes('cv.md not found')) {\n    console.error('Create cv.md in the repo root (or run onboarding) before adding CV entries');\n  } else throw e;\n}","preventionTips":["Check cv.md existence (fs.existsSync / doctor.mjs) before running any add flow.","Never swallow file-read errors into a null return — let ENOENT surface or handle it explicitly.","Remember the asymmetry: article-digest.md is auto-created, cv.md is not — treat cv.md as a hard prerequisite."],"tags":["file","missing-file","precondition"],"backgroundTag":"file-not-found","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"}