{"record":{"id":"7fc31b08b211a6ab","repo":"can1357/oh-my-pi","slug":"invalid-surface-raw-valid-values-galler","errorCode":null,"errorMessage":"Invalid --surface '${raw}'. Valid values: ${GALLERY_SURFACE_TOKENS.join(\", \")}","messagePattern":"Invalid --surface '(.+?)'\\. Valid values: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/cli/gallery-cli.ts","lineNumber":71,"sourceCode":"export const GALLERY_STATE_TOKENS = Object.keys(GALLERY_STATE_ALIASES);\n\n/** Gallery surfaces in stable product order. */\nexport const GALLERY_SURFACES = [\"tool\", \"composer\", \"segment\"] as const;\nexport type GallerySurface = (typeof GALLERY_SURFACES)[number];\nexport const GALLERY_SURFACE_TOKENS = [...GALLERY_SURFACES, \"all\"] as const;\n\n/** Expand user-provided surface tokens while preserving product order. */\nexport function parseGallerySurfaces(surfaces: readonly string[] | undefined): GallerySurface[] | undefined {\n\tif (!surfaces || surfaces.length === 0) return undefined;\n\tconst requested = new Set<GallerySurface>();\n\tfor (const raw of surfaces) {\n\t\tconst token = raw.trim().toLowerCase();\n\t\tif (token === \"all\") {\n\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;","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/cli/gallery-cli.ts#L53-L89","documentation":"parseGallerySurfaces validates each comma-separated token of the --surface flag against the known GALLERY_SURFACES list (plus the 'all' shorthand). Unknown tokens abort with the raw token and the full list of valid values. Matching is case-insensitive (tokens are trimmed and lowercased), but must still be exact strings from the list.","triggerScenarios":"`omp gallery --surface agentsx`, `--surface tools,agentz` (one bad token fails the whole list), or a surface renamed in a newer version so an old script's token no longer matches.","commonSituations":"Guessing surface names instead of copying from --help, pluralizing a singular surface name (`--surface agents` when only `agent` exists), or scripts breaking after a surface token was renamed/removed in an update.","solutions":["Use only tokens listed in the error's 'Valid values:' part, or 'all' for every surface","Copy names exactly from `omp gallery --help`; matching is lowercase and trimmed but must be the exact token","Split multi-value flags and test each token if unsure which one is bad","If a previously working token broke, check the changelog/help for a renamed surface and update the script"],"exampleFix":"// before\nomp gallery --surface agents,tools\n// after\nomp gallery --surface agent,tools   # or --surface all","handlingStrategy":"validation","validationCode":"const GALLERY_SURFACES = ['agent','tools' /* see omp gallery --help for the exact list */];\nfunction assertSurfaces(raw) {\n  for (const token of raw.split(',')) {\n    const t = token.trim().toLowerCase();\n    if (t !== 'all' && !GALLERY_SURFACES.includes(t))\n      throw new Error(`Invalid --surface '${token}'. Valid: ${GALLERY_SURFACES.join(', ')}`);\n  }\n}","typeGuard":"type GallerySurface = (typeof GALLERY_SURFACES)[number];\nconst isGallerySurface = (t: string): t is GallerySurface =>\n  (GALLERY_SURFACES as readonly string[]).includes(t);","tryCatchPattern":"try {\n  parse(['--surface', raw]);\n} catch (e) {\n  if (/Invalid --surface/.test((e as Error).message)) {\n    console.error(`Bad token: ${e.message.match(/'([^']+)'/)?.[1]}. Valid values: ${e.message.match(/Valid values: (.+)$/)?.[1]}`);\n  } else throw e;\n}","preventionTips":["Copy surface names exactly from --help; do not pluralize or guess","Remember each comma-separated token is validated — one bad token fails all","Re-check scripts after upgrades in case surface tokens were renamed; use 'all' when you want everything"],"tags":["cli","argument-validation","gallery","flag-parsing"],"backgroundTag":"invalid-enum-value","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}