{"record":{"id":"50c4b7c13c88864a","repo":"withfig/autocomplete","slug":"failed-to-parse-alias","errorCode":null,"errorMessage":"Failed to parse alias","messagePattern":"Failed to parse alias","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/gh.ts","lineNumber":274,"sourceCode":"  name: \"gh\",\n  description: \"GitHub's CLI tool\",\n  args: {\n    name: \"alias\",\n    description: \"Custom user defined gh alias\",\n    isOptional: true,\n    generators: ghGenerators.listAlias,\n    parserDirectives: {\n      alias: async (token, executeShellCommand) => {\n        const { stdout } = await executeShellCommand({\n          command: \"gh\",\n          args: [\"alias\", \"list\"],\n        });\n        const alias = stdout\n          .split(\"\\n\")\n          .find((line) => line.startsWith(`${token}:\\t`));\n\n        if (!alias) {\n          throw new Error(\"Failed to parse alias\");\n        }\n\n        return alias.slice(token.length + 1).trim();\n      },\n    },\n  },\n  subcommands: [\n    {\n      name: \"alias\",\n      description: \"Create command shortcuts\",\n\n      subcommands: [\n        {\n          name: \"delete\",\n          description: \"Delete an alias\",\n          args: {\n            name: \"alias\",\n            generators: ghGenerators.listAlias,","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/withfig/autocomplete/blob/aef52acff84c45edde61ae610cc2c964802b9a38/src/gh.ts#L256-L292","documentation":"In this Fig-style completion spec, a generator runs `gh alias list`, splits the output by lines, and looks for a line beginning with `<token>:\\t` (name, colon, tab). If no line matches — meaning GitHub CLI returned no alias with that name or its output format differs — the spec throws this Error to abort alias completion.","triggerScenarios":"The `token` argument does not match any alias name printed by `gh alias list`; `gh` prints aliases in a different format (e.g. no tab separator after the colon, older gh versions); or the generator's `gh alias list` command silently succeeds with empty output while an alias lookup was expected.","commonSituations":"User typed an alias name with different casing or a typo; gh CLI is not authenticated or has no aliases configured; a gh version change altered `gh alias list` output formatting (removed the tab); user defined aliases only in git but not gh.","solutions":["Run `gh alias list` and confirm an alias with exactly the typed name exists (`gh alias list | grep '^name:'`)","Create the missing alias with `gh alias set <name> '<command>'`","Check for whitespace/format drift: if your gh version does not emit a tab after the colon, relax the prefix match in the spec","Verify `gh` is on PATH and authenticated (`gh auth status`) so the generator's command succeeds"],"exampleFix":"// before\nconst alias = stdout\n  .split(\"\\n\")\n  .find((line) => line.startsWith(`${token}:\\t`));\n// after (tolerant of tab or spaces after the colon)\nconst alias = stdout\n  .split(\"\\n\")\n  .find((line) => new RegExp(`^${token}:\\\\s`).test(line));","handlingStrategy":"validation","validationCode":"import { execSync } from \"child_process\";\nexport function ghAliasExists(token: string): boolean {\n  try {\n    const out = execSync(\"gh alias list\", { encoding: \"utf8\" });\n    return new RegExp(`^${token}:\\\\s`, \"m\").test(out);\n  } catch {\n    return false;\n  }\n}\nif (!ghAliasExists(\"co\")) throw new Error(\"gh alias 'co' not configured\");","typeGuard":"function isAliasLine(line: string, token: string): line is `${string}:\\t${string}` {\n  return line.startsWith(`${token}:\\t`) || new RegExp(`^${token}:\\\\s`).test(line);\n}","tryCatchPattern":"try {\n  const script = await getAlias(token);\n} catch (err) {\n  if (err instanceof Error && err.message === \"Failed to parse alias\") {\n    // treat as \"no such alias\": suggest `gh alias list` or fall back to default completions\n    return [];\n  }\n  throw err;\n}","preventionTips":["Verify `gh alias list` output before relying on alias completion","Quote/normalize the token (trim whitespace, match casing) before lookup","Keep gh CLI updated and re-check parsing after gh upgrades","Fallback to empty completions instead of treating missing alias as fatal"],"tags":["cli","gh-cli","parsing","autocomplete-generator"],"backgroundTag":"shell-command-output-unparseable","analyzedSha":"aef52acff84c45edde61ae610cc2c964802b9a38","analyzedAt":"2026-08-31T11:00:43.303Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}