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

  1. Check available subcommands with `hub help <command>` and fix the spelling.
  2. If the first positional argument was not meant to be a subcommand, invoke the command differently (quote or reorder args).
  3. 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

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


AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01). Data as JSON: /api/errors/b00047f0ec2a2667. Report an issue: GitHub.