mislav/hub · error
error: Unknown subcommand: %s
Error message
error: Unknown subcommand: %s
What it means
lookupSubCommand in commands/commands.go resolves the first parameter against the command's registered subCommands map. When the command has subcommands and args.HasSubcommand() is true but the name is not a key in the map, it returns "error: Unknown subcommand: <name>".
Source
Thrown at commands/commands.go:155
if c.Key != "" {
return c.Key
}
usageLine := strings.Split(strings.TrimSpace(c.Usage), "\n")[0]
return strings.Split(usageLine, " ")[0]
}
func (c *Command) Runnable() bool {
return c.Run != nil
}
func (c *Command) lookupSubCommand(args *Args) (runCommand *Command, err error) {
if len(c.subCommands) > 0 && args.HasSubcommand() {
subCommandName := args.FirstParam()
if subCommand, ok := c.subCommands[subCommandName]; ok {
runCommand = subCommand
args.Params = args.Params[1:]
} else {
err = fmt.Errorf("error: Unknown subcommand: %s", subCommandName)
}
} else {
runCommand = c
}
return
}
View on GitHub (pinned to 5c547ed804)
Solutions
- Check available subcommands with `hub help <command>` and fix the spelling.
- If the first positional argument was not meant to be a subcommand, invoke the command differently (quote or reorder args).
- Upgrade hub if the subcommand exists only in newer releases.
Example fix
// before hub gist lst // error: Unknown subcommand: lst // after hub gist list
Defensive patterns
Strategy: try-catch
Validate before calling
// confirm the subcommand exists before dispatch
if cmd, ok := parent.subCommands[name]; !ok {
fmt.Fprintf(os.Stderr, "available: %v\n", keys(parent.subCommands))
os.Exit(2)
} Try / catch
err := command.Call(args)
if err != nil && strings.HasPrefix(err.Error(), "error: Unknown subcommand:") {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
} Prevention
- List subcommands with `hub help <command>` before scripting
- Avoid passing arbitrary positional args to commands that have subcommands
- Watch for typos in subcommand names in shell scripts
When it happens
Trigger: Invoking `hub <command> <word>` where <command> declares subCommands, <word> is taken as the subcommand name (args.FirstParam()), and the map lookup fails.
Common situations: Typing `hub ci status`-style invocations on commands without that subcommand; typos (`hub gist lst`); passing an unexpected positional argument that gets misinterpreted as a subcommand; using a subcommand added in a newer hub version.
Related errors
- Error: couldn't detect shell type. Please specify your shell
- hub alias: unsupported shell supported shells: %s
- Unsupported flag -b when checking out pull request
- Unsupported flag --orphan when checking out pull request
- Aborted: no revision could be determined from '%s'
AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01).
Data as JSON: /api/errors/b00047f0ec2a2667.
Report an issue: GitHub.