{"record":{"id":"d1729911ea1159e7","repo":"can1357/oh-my-pi","slug":"invalid-state-raw-valid-values-gallery","errorCode":null,"errorMessage":"Invalid --state '${raw}'. Valid values: ${GALLERY_STATE_TOKENS.join(\", \")}","messagePattern":"Invalid --state '(.+?)'\\. Valid values: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/cli/gallery-cli.ts","lineNumber":85,"sourceCode":"\t\t\tfor (const surface of GALLERY_SURFACES) requested.add(surface);\n\t\t\tcontinue;\n\t\t}\n\t\tif (!GALLERY_SURFACES.includes(token as GallerySurface)) {\n\t\t\tthrow new Error(`Invalid --surface '${raw}'. Valid values: ${GALLERY_SURFACE_TOKENS.join(\", \")}`);\n\t\t}\n\t\trequested.add(token as GallerySurface);\n\t}\n\treturn GALLERY_SURFACES.filter(surface => requested.has(surface));\n}\n\n/** Normalize user-provided `--state` tokens to the internal gallery lifecycle states. */\nexport function parseGalleryStates(states: readonly string[] | undefined): GalleryState[] | undefined {\n\tif (!states || states.length === 0) return undefined;\n\tconst parsed: GalleryState[] = [];\n\tfor (const raw of states) {\n\t\tconst state = GALLERY_STATE_ALIASES[raw.trim().toLowerCase()];\n\t\tif (!state) {\n\t\t\tthrow new Error(`Invalid --state '${raw}'. Valid values: ${GALLERY_STATE_TOKENS.join(\", \")}`);\n\t\t}\n\t\tif (!parsed.includes(state)) parsed.push(state);\n\t}\n\treturn parsed;\n}\n\nexport interface GalleryCommandArgs {\n\t/** Render width in columns (defaults to terminal width, clamped). */\n\twidth?: number;\n\t/** Restrict rendering to selected surface types (defaults to all). */\n\tsurfaces?: GallerySurface[];\n\t/** Restrict to a single tool name. */\n\ttool?: string;\n\t/** Restrict to a single composer shape. */\n\tcomposer?: string;\n\t/** Restrict to a single status-line segment. */\n\tsegment?: string;\n\t/** Restrict to specific lifecycle states. */","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/cli/gallery-cli.ts#L67-L103","documentation":"parseGalleryStates validates the --state CLI flag for `omp gallery`. It looks each comma/whitespace-separated token up in GALLERY_STATE_ALIASES (case-insensitive, trimmed); any token not present in the alias table throws immediately so the user sees the full list of valid values instead of getting an empty/partial gallery.","triggerScenarios":"Running `omp gallery --state <unknown>` with a token that is not in GALLERY_STATE_ALIASES — e.g. a typo like `--state archivd`, an unsupported synonym like `--state old`, or a value quoted with stray characters.","commonSituations":"Typing a state name from memory; copying flags from docs for a different version where the alias table changed; passing a value with extra punctuation or a non-lowercased variant that is genuinely not an alias.","solutions":["Run `omp gallery --help` (or read GALLERY_STATE_TOKENS in the error message) and use one of the listed tokens","Fix the typo in the --state value; matching is case-insensitive so casing is fine but spelling must match an alias","If a legitimate state is missing from the table, add it to GALLERY_STATE_ALIASES/GALLERY_STATE_TOKENS in gallery-cli.ts"],"exampleFix":"// before\nomp gallery --state archivd\n// after\nomp gallery --state archived","handlingStrategy":"validation","validationCode":"const VALID = new Set([\"current\",\"archived\",\"all\"]); // GALLERY_STATE_TOKENS\nconst states = (raw ?? \"\").split(\",\").map(s => s.trim().toLowerCase());\nif (states.some(s => !VALID.has(s))) throw new Error(`--state must be one of: ${[...VALID].join(\", \")}`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Copy state tokens from --help output or GALLERY_STATE_TOKENS rather than typing from memory","Pre-validate flag values in shell scripts before invoking the CLI","Use shell completion / tab completion where available"],"tags":["cli","validation","argument-parsing"],"backgroundTag":"invalid-cli-argument","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}