{"record":{"id":"8b5fb02b64f2dc2e","repo":"santifer/career-ops","slug":"payload-articledigest-requires-a-non-empty-dedupke","errorCode":null,"errorMessage":"payload.articleDigest requires a non-empty dedupKey (used for dedup/idempotency)","messagePattern":"payload\\.articleDigest requires a non-empty dedupKey \\(used for dedup/idempotency\\)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"add-entry.mjs","lineNumber":196,"sourceCode":"  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' };\n      articleDigest = articleText;\n    } else {\n      articleDigest = appendArticleDigest(current, entry);\n      result.articleDigest = { status: articleText === null ? 'created' : 'added' };\n    }\n  }\n\n  return { cv, articleDigest, result };\n}\n\nasync function readStdin() {\n  const chunks = [];","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/add-entry.mjs#L178-L214","documentation":"add-entry.mjs throws this when a caller passes payload.articleDigest but omits dedupKey or supplies one that normalizes to empty. dedupKey is the identity used by articleDigestHasEntry to detect duplicate entries and make the write idempotent, so the library refuses to proceed without it. It is an input-contract violation, not a filesystem problem.","triggerScenarios":"Calling applyAdd (or the add-entry CLI path) with payload.articleDigest = { entry } but no dedupKey, with dedupKey: undefined/null/'', or with a dedupKey that is only whitespace after normalization. Often happens when building the payload programmatically and the field that should feed dedupKey (e.g. a slug or URL) is undefined.","commonSituations":"Scripting bulk imports of portfolio proof points into article-digest.md where some source objects lack an identifier field; renaming a payload field (id -> dedupKey) and forgetting to update construction sites; template literals interpolating an empty variable into the key.","solutions":["Set a non-empty, stable dedupKey in the payload (e.g. a slug of the article title, the source URL, or a project+metric key) so repeat runs are treated as duplicates instead of re-added.","Verify the value feeding dedupKey is defined and non-blank before calling applyAdd (log or assert it).","If you only wanted to append a CV entry, check you did not accidentally nest it under payload.articleDigest; that branch has different requirements."],"exampleFix":"// before\napplyAdd({ payload: { articleDigest: { entry } } });\n// after\nconst dedupKey = slugify(article.title);\nif (!dedupKey) throw new Error('cannot derive dedupKey from article title');\napplyAdd({ payload: { articleDigest: { dedupKey, entry } } });","handlingStrategy":"validation","validationCode":"function hasDedupKey(payload) {\n  return Boolean(payload?.articleDigest?.dedupKey && String(payload.articleDigest.dedupKey).trim());\n}\nif (!hasDedupKey(payload)) throw new Error('articleDigest payload needs a non-empty dedupKey');","typeGuard":"function hasArticleDigestPayload(p) {\n  return typeof p?.articleDigest?.dedupKey === 'string' && p.articleDigest.dedupKey.trim() !== '' && p.articleDigest.entry != null;\n}","tryCatchPattern":null,"preventionTips":["Derive dedupKey from a stable source field (URL or slugified title) and assert it before building the payload.","Write a unit test that constructs every payload variant your scripts produce and asserts hasDedupKey.","Never pass user-typed raw strings as dedupKey without trimming and checking for emptiness."],"tags":["validation","idempotency","node"],"backgroundTag":"empty-required-field","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"}