withfig/autocomplete · error · Error
Failed to parse alias
Error message
Failed to parse alias
What it means
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.
Source
Thrown at src/gh.ts:274
name: "gh",
description: "GitHub's CLI tool",
args: {
name: "alias",
description: "Custom user defined gh alias",
isOptional: true,
generators: ghGenerators.listAlias,
parserDirectives: {
alias: async (token, executeShellCommand) => {
const { stdout } = await executeShellCommand({
command: "gh",
args: ["alias", "list"],
});
const alias = stdout
.split("\n")
.find((line) => line.startsWith(`${token}:\t`));
if (!alias) {
throw new Error("Failed to parse alias");
}
return alias.slice(token.length + 1).trim();
},
},
},
subcommands: [
{
name: "alias",
description: "Create command shortcuts",
subcommands: [
{
name: "delete",
description: "Delete an alias",
args: {
name: "alias",
generators: ghGenerators.listAlias,View on GitHub (pinned to aef52acff8)
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
Example fix
// before
const alias = stdout
.split("\n")
.find((line) => line.startsWith(`${token}:\t`));
// after (tolerant of tab or spaces after the colon)
const alias = stdout
.split("\n")
.find((line) => new RegExp(`^${token}:\\s`).test(line)); Defensive patterns
Strategy: validation
Validate before calling
import { execSync } from "child_process";
export function ghAliasExists(token: string): boolean {
try {
const out = execSync("gh alias list", { encoding: "utf8" });
return new RegExp(`^${token}:\\s`, "m").test(out);
} catch {
return false;
}
}
if (!ghAliasExists("co")) throw new Error("gh alias 'co' not configured"); Type guard
function isAliasLine(line: string, token: string): line is `${string}:\t${string}` {
return line.startsWith(`${token}:\t`) || new RegExp(`^${token}:\\s`).test(line);
} Try / catch
try {
const script = await getAlias(token);
} catch (err) {
if (err instanceof Error && err.message === "Failed to parse alias") {
// treat as "no such alias": suggest `gh alias list` or fall back to default completions
return [];
}
throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
AI-assisted analysis of withfig/autocomplete@aef52acff8 (2026-08-31).
Data as JSON: /api/errors/50c4b7c13c88864a.
Report an issue: GitHub.