withfig/autocomplete · error · Error
Failed parsing alias
Error message
Failed parsing alias
What it means
This generator resolves a git alias by running `git config --get alias.<token>`. `git config --get` exits non-zero when the requested key does not exist (or config is unreadable), so the spec throws this Error to signal that the typed token is not a configured git alias.
Source
Thrown at src/git.ts:4064
return {
name: "git",
subcommands: commands.map((name) => ({
name,
...(optionalCommands[name] ?? { description: `Run git-${name}` }),
})),
};
},
args: {
name: "alias",
description: "Custom user defined git alias",
parserDirectives: {
alias: async (token, exec) => {
const { stdout, status } = await exec({
command: "git",
args: ["config", "--get", `alias.${token}`],
});
if (status !== 0) {
throw new Error("Failed parsing alias");
}
return stdout;
},
},
isOptional: true,
generators: gitGenerators.aliases,
},
options: [
{
name: "--version",
description: "Output version",
},
{
name: "--help",
description: "Output help",
},
{
name: "-C",View on GitHub (pinned to aef52acff8)
Solutions
- Run `git config --get alias.<token>` manually to confirm the alias exists
- Add the alias with `git config --global alias.<token> '<command>'`
- Check `git config --list | grep alias` to see all defined aliases and their exact names
- Ensure the git config file is readable and not corrupted (`git config --list` exits 0)
Defensive patterns
Strategy: try-catch
Validate before calling
import { execSync } from "child_process";
export function gitAliasExists(token: string): boolean {
try {
execSync(`git config --get alias.${token}`, { stdio: "ignore" });
return true;
} catch {
return false;
}
} Try / catch
try {
const cmd = await resolveGitAlias(token);
} catch (err) {
if (err instanceof Error && err.message === "Failed parsing alias") {
// non-zero exit from `git config --get`: token is not a git alias
return suggestBuiltins(token); // graceful degradation
}
throw err;
} Prevention
- Check `git config --get alias.<token>` exit status before calling the generator
- List aliases with `git config --get-regexp '^alias\\.'` to see valid tokens
- Distinguish 'alias not found' (exit 1) from 'config unreadable' (other codes) when handling
- Remember the spec is optional (isOptional: true) — treat its failure as empty suggestions
When it happens
Trigger: `git config --get alias.<token>` exits with status !== 0 — i.e. no alias named `token` exists in any config scope, or the git config file cannot be read/parsed.
Common situations: User typed a command that is a built-in git command, shell function, or gh alias but not a git config alias; alias defined with different name/casing; repo-level alias expected but defined only globally (or vice versa — though --get searches all scopes); corrupted or unreadable .gitconfig.
Related errors
AI-assisted analysis of withfig/autocomplete@aef52acff8 (2026-08-31).
Data as JSON: /api/errors/cb669c7808704df4.
Report an issue: GitHub.