{"record":{"id":"82435f34116c6ea9","repo":"Yeachan-Heo/oh-my-codex","slug":"answers-entry-index-answer-must-select-exactly","errorCode":null,"errorMessage":"answers[${entry.index}].answer must select exactly one option","messagePattern":"answers\\[(.+?)\\]\\.answer must select exactly one option","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/question/state.ts","lineNumber":387,"sourceCode":"  if (answer.kind === 'other') {\n    if (!question.allow_other) throw new Error(`answers[${entry.index}].answer.kind=other is not allowed for this question`);\n    if (multi) throw new Error(`answers[${entry.index}].answer.kind=other is only valid for single-answerable questions`);\n    if (!otherText) throw new Error(`answers[${entry.index}].answer.other_text must be a non-empty string`);\n    if (selectedValues.length !== 1 || selectedValues[0] !== otherText || answer.value !== otherText) {\n      throw new Error(`answers[${entry.index}].answer other value must match selected_values[0] and other_text`);\n    }\n    assertSelectedLabelsMatch(\n      selectedLabels,\n      [question.other_label],\n      `answers[${entry.index}].answer.selected_labels`,\n    );\n    return;\n  }\n\n  if (answer.kind === 'option') {\n    if (multi) throw new Error(`answers[${entry.index}].answer.kind=option is only valid for single-answerable questions`);\n    if (selectedValues.length !== 1 || selectedLabels.length !== 1) {\n      throw new Error(`answers[${entry.index}].answer must select exactly one option`);\n    }\n    const selectedValue = selectedValues[0]!;\n    if (!optionValues.has(selectedValue)) {\n      throw new Error(`answers[${entry.index}].answer selected value is not in the option schema: ${selectedValue}`);\n    }\n    if (answer.value !== selectedValue) {\n      throw new Error(`answers[${entry.index}].answer.value must match selected_values[0]`);\n    }\n    assertSelectedLabelsMatch(\n      selectedLabels,\n      expectedSelectedLabelsForValues(question, selectedValues, undefined),\n      `answers[${entry.index}].answer.selected_labels`,\n    );\n    return;\n  }\n\n  if (!multi) throw new Error(`answers[${entry.index}].answer.kind=multi is only valid for multi-answerable questions`);\n  if (!Array.isArray(answer.value)) throw new Error(`answers[${entry.index}].answer.value must be an array for multi answers`);","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/question/state.ts#L369-L405","documentation":"An option-kind answer must contain exactly one selected value and exactly one selected label. Zero selections or more than one throws this error.","triggerScenarios":"kind 'option' with selected_values.length !== 1 or selected_labels.length !== 1, e.g. submitting with nothing selected, or two values stuffed into a single-select answer.","commonSituations":"Submit button enabled with no selection; single-select widget accidentally accumulating multiple selections; porting a multi-select UI onto an option-kind payload.","solutions":["Disable submit until exactly one option is chosen for option-kind answers","Reset/clear selection state when the question changes so old selections don't accumulate"],"exampleFix":"// before\nif (selection.length >= 1) submit({ kind: 'option', selected_values: selection });\n// after\nif (selection.length === 1) submit({ kind: 'option', selected_values: selection, selected_labels: labels });\nelse showError('Pick exactly one option');","handlingStrategy":"validation","validationCode":"if (answer.kind === 'option' && (answer.selected_values.length !== 1 || answer.selected_labels.length !== 1)) throw new Error('pick exactly one');","typeGuard":"function exactlyOne(arr: unknown[]): boolean { return arr.length === 1; }","tryCatchPattern":"try { await submit(p, answers); } catch (e) { if (/must select exactly one option/.test((e as Error).message)) { blockSubmitUntilOneSelected(); return; } throw e; }","preventionTips":["Disable submit until a single selection exists","Clear stale selections when the question changes"],"tags":["validation","cardinality","answers"],"backgroundTag":"schema-validation-failed","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}