{"record":{"id":"ecd5f5e628fd3dc4","repo":"can1357/oh-my-pi","slug":"expected-name-to-be-one-of-desc-option","errorCode":null,"errorMessage":"Expected --${name} to be one of: ${[...desc.options].join(\", \")}; got \"${val}\"","messagePattern":"Expected --(.+?) to be one of: (.+?); got \"(.+?)\"","errorType":"validation","errorClass":"CliUsageError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/cli.ts","lineNumber":246,"sourceCode":"\t\t\t\tif (raw === undefined || typeof raw === \"boolean\") {\n\t\t\t\t\tflags[name] = desc.default ?? undefined;\n\t\t\t\t} else {\n\t\t\t\t\tconst n = Number.parseInt(raw as string, 10);\n\t\t\t\t\tif (Number.isNaN(n)) {\n\t\t\t\t\t\tthrow new CliUsageError(`Expected integer for --${name}, got \"${raw}\"`);\n\t\t\t\t\t}\n\t\t\t\t\tflags[name] = n;\n\t\t\t\t}\n\t\t\t} else if (desc.kind === \"boolean\") {\n\t\t\t\tflags[name] =\n\t\t\t\t\traw !== undefined ? Boolean(raw) : desc.default !== undefined ? Boolean(desc.default) : undefined;\n\t\t\t} else {\n\t\t\t\t// string\n\t\t\t\tconst val = raw !== undefined && typeof raw !== \"boolean\" ? raw : (desc.default ?? undefined);\n\t\t\t\t// Validate options constraint\n\t\t\t\tif (val !== undefined && desc.options && !Array.isArray(val)) {\n\t\t\t\t\tif (!desc.options.includes(val as string)) {\n\t\t\t\t\t\tthrow new CliUsageError(\n\t\t\t\t\t\t\t`Expected --${name} to be one of: ${[...desc.options].join(\", \")}; got \"${val}\"`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tflags[name] = val;\n\t\t\t}\n\t\t\t// Validate required\n\t\t\tif (desc.required && flags[name] === undefined) {\n\t\t\t\tthrow new CliUsageError(`Missing required flag: --${name}`);\n\t\t\t}\n\t\t}\n\n\t\t// Map positionals to named args in declaration order and validate\n\t\tconst args: Record<string, unknown> = {};\n\t\tlet posIdx = 0;\n\t\tfor (const [argName, desc] of Object.entries(argDefs)) {\n\t\t\tif (desc.multiple) {\n\t\t\t\tconst val = positionals.slice(posIdx);","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/cli.ts#L228-L264","documentation":"parse() enforces the `options` constraint on string flags: if the flag declares an allowed set and the provided value is not in it, a CliUsageError listing the valid choices is thrown.","triggerScenarios":"Passing a value to an enum-constrained flag that is not one of the declared options, e.g. `--format xml` when options are [\"json\",\"text\"], or a value that differs only in case.","commonSituations":"Users guessing valid values, mixing up case (--Level vs level), or using values valid in an older CLI version whose enum was renamed.","solutions":["Use one of the listed allowed values exactly as shown in the error message.","Match the case of the declared options (comparison is case-sensitive).","Run --help to see the current allowed values.","If the value should be legal, extend desc.options in the flag definition."],"exampleFix":"// before\ncli.parse(['--format', 'yaml']); // not in options\n// after\ncli.parse(['--format', 'json']);","handlingStrategy":"validation","validationCode":"const allowed = ['json', 'text'];\nif (!allowed.includes(formatValue)) {\n  throw new Error(`--format must be one of: ${allowed.join(', ')}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const { format } = cli.parse(argv);\n} catch (err) {\n  if (err instanceof CliUsageError && err.message.includes('to be one of')) {\n    console.error(err.message);\n    process.exitCode = 2;\n    return;\n  }\n  throw err;\n}","preventionTips":["Copy allowed values verbatim from --help.","Remember comparisons are case-sensitive.","Use shell completion or a wrapper script that constrains values."],"tags":["cli","validation","enum","argument-parsing"],"backgroundTag":"invalid-enum-value","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}