mislav/hub · error

%s%s%s

Error message

%s%s%s

What it means

Command.UsageError in commands/commands.go builds an error whose text is the caller-supplied message plus a blank line plus the command's Synopsis (usage text). It is used by subcommands (browse, compare, create, deleteRepo, printGistHelp, showGist) to report invalid invocation while showing how to use the command.

Source

Thrown at commands/commands.go:90

	args.Params = rest
	args.Terminator = args.Flag.HasTerminated
	return nil
}

func (c *Command) Use(subCommand *Command) {
	if c.subCommands == nil {
		c.subCommands = make(map[string]*Command)
	}
	c.subCommands[subCommand.Name()] = subCommand
	subCommand.parentCommand = c
}

func (c *Command) UsageError(msg string) error {
	nl := ""
	if msg != "" {
		nl = "\n"
	}
	return fmt.Errorf("%s%s%s", msg, nl, c.Synopsis())
}

func (c *Command) Synopsis() string {
	lines := []string{}
	usagePrefix := "Usage:"
	usageStr := c.Usage
	if usageStr == "" && c.parentCommand != nil {
		usageStr = c.parentCommand.Usage
	}

	for _, line := range strings.Split(usageStr, "\n") {
		if line != "" {
			usage := fmt.Sprintf("%s hub %s", usagePrefix, line)
			usagePrefix = "      "
			lines = append(lines, usage)
		}
	}
	return strings.Join(lines, "\n")

View on GitHub (pinned to 5c547ed804)

Solutions

  1. Read the usage/synopsis printed with the message and supply the missing or correct flags.
  2. Run `hub help <command>` or `<command> --help` to see all accepted forms.
  3. Split the invocation into the mode the usage text describes instead of mixing flags.

Example fix

// before
hub compare --base master    // UsageError: missing branch to compare
// after
hub compare --base master feature-branch
Defensive patterns

Strategy: validation

Validate before calling

// ensure required flags/args exist before calling the command
if flagCompareBase == "" && len(args.Params) < 1 {
    return cmd.UsageError("missing branch to compare")
}

Try / catch

if err := cmd.Call(args); err != nil {
    if strings.Contains(err.Error(), "Usage:") {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(2)
    }
}

Prevention

When it happens

Trigger: Any subcommand calling command.UsageError(msg): required flags missing, mutually exclusive flags combined (e.g. compare given --base alongside invalid args for its no-arg mode), or arguments in a form the command does not accept.

Common situations: Running `hub compare --base master` without the branch arg it needs; mixing flags that only apply to another invocation mode; forgetting a required flag like -m for create/delete flows.

Related errors


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