{"record":{"id":"b9fd59f95fc44b9c","repo":"santifer/career-ops","slug":"application-answer-state-must-be-one-of-val","errorCode":null,"errorMessage":"Application answer state must be one of: ${[...VALID_STATES].join(', ')}","messagePattern":"Application answer state must be one of: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"application-answers.mjs","lineNumber":39,"sourceCode":"  for (const key of keys) {\n    const value = object?.[key];\n    if (Array.isArray(value)) {\n      if (value.length > 0) return value;\n      continue;\n    }\n    if (value !== undefined && value !== null && String(value).trim()) return value;\n  }\n  return '';\n}\n\nfunction list(value) {\n  return Array.isArray(value) ? value : [];\n}\n\nfunction normalizeState(state) {\n  const normalized = inline(state || 'filled').toLowerCase();\n  if (!VALID_STATES.has(normalized)) {\n    throw new Error(`Application answer state must be one of: ${[...VALID_STATES].join(', ')}`);\n  }\n  return normalized;\n}\n\nfunction normalizeDate(date) {\n  return inline(date || new Date().toISOString().slice(0, 10));\n}\n\nfunction quoteBlock(value) {\n  const text = String(value ?? '').replace(/\\r\\n/g, '\\n').trim();\n  if (!text) return '> Not recorded.';\n  return text.split('\\n').map((line) => `> ${line}`).join('\\n');\n}\n\nfunction qaLines(entries, { labelKeys, valueKeys, fallback }) {\n  if (entries.length === 0) return ['- None captured.'];\n\n  return entries.flatMap((entry, index) => {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/application-answers.mjs#L21-L57","documentation":"application-answers.mjs validates the application answer state against the fixed set VALID_STATES = {'filled','submitted'}. normalizeState lowercases the input and throws when it is not a member, listing the allowed values in the message. This keeps the application-answers snapshot file limited to canonical states.","triggerScenarios":"Calling normalizeState or any API that routes state through it (write/save of an application answer record) with state values like 'draft', 'complete', 'FILLED ' that isn't in the set, an empty string, or a boolean/number instead of a string.","commonSituations":"Migrating from another tool whose states were 'draft'/'done'; typo-ing 'submited'; wiring a UI dropdown that emits different labels; hand-editing the JSON state file with a non-canonical state.","solutions":["Change the state string to a canonical value: 'filled' or 'submitted' (case-insensitive; input is lowercased).","Map foreign state names to canonical ones at the boundary before saving, e.g. draft -> filled, done/sent -> submitted.","Print VALID_STATES or read the error message to see the exact allowed set before retrying."],"exampleFix":"// before\nsaveAnswers({ state: 'draft', answers });\n// after\nconst ALIASES = { draft: 'filled', done: 'submitted', sent: 'submitted' };\nconst state = ALIASES[rawState] ?? rawState;\nsaveAnswers({ state, answers });","handlingStrategy":"validation","validationCode":"const VALID_STATES = new Set(['filled', 'submitted']);\nif (!VALID_STATES.has(String(state || 'filled').toLowerCase())) {\n  throw new Error(`state must be filled or submitted, got: ${state}`);\n}","typeGuard":"function isCanonicalAnswerState(v) {\n  return typeof v === 'string' && ['filled', 'submitted'].includes(v.toLowerCase());\n}","tryCatchPattern":"try {\n  saveAnswers({ state, answers });\n} catch (err) {\n  if (String(err.message).startsWith('Application answer state must be one of')) {\n    console.error(`Invalid state \"${state}\"; use filled or submitted`);\n    process.exitCode = 2;\n    return;\n  }\n  throw err;\n}","preventionTips":["Keep a single ALIASES map converting any foreign state names ('draft', 'done') to canonical values at every boundary.","Lowercase and trim state strings before passing them into library calls.","Add a lint/test asserting every state literal in your codebase is in {filled, submitted}."],"tags":["validation","enum","node"],"backgroundTag":"invalid-enum-value","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"}