{"record":{"id":"e797a9af42543819","repo":"mislav/hub","slug":"s-s-s","errorCode":null,"errorMessage":"%s%s%s","messagePattern":"%s%s%s","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/commands.go","lineNumber":90,"sourceCode":"\targs.Params = rest\n\targs.Terminator = args.Flag.HasTerminated\n\treturn nil\n}\n\nfunc (c *Command) Use(subCommand *Command) {\n\tif c.subCommands == nil {\n\t\tc.subCommands = make(map[string]*Command)\n\t}\n\tc.subCommands[subCommand.Name()] = subCommand\n\tsubCommand.parentCommand = c\n}\n\nfunc (c *Command) UsageError(msg string) error {\n\tnl := \"\"\n\tif msg != \"\" {\n\t\tnl = \"\\n\"\n\t}\n\treturn fmt.Errorf(\"%s%s%s\", msg, nl, c.Synopsis())\n}\n\nfunc (c *Command) Synopsis() string {\n\tlines := []string{}\n\tusagePrefix := \"Usage:\"\n\tusageStr := c.Usage\n\tif usageStr == \"\" && c.parentCommand != nil {\n\t\tusageStr = c.parentCommand.Usage\n\t}\n\n\tfor _, line := range strings.Split(usageStr, \"\\n\") {\n\t\tif line != \"\" {\n\t\t\tusage := fmt.Sprintf(\"%s hub %s\", usagePrefix, line)\n\t\t\tusagePrefix = \"      \"\n\t\t\tlines = append(lines, usage)\n\t\t}\n\t}\n\treturn strings.Join(lines, \"\\n\")","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/commands/commands.go#L72-L108","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the usage/synopsis printed with the message and supply the missing or correct flags.","Run `hub help <command>` or `<command> --help` to see all accepted forms.","Split the invocation into the mode the usage text describes instead of mixing flags."],"exampleFix":"// before\nhub compare --base master    // UsageError: missing branch to compare\n// after\nhub compare --base master feature-branch","handlingStrategy":"validation","validationCode":"// ensure required flags/args exist before calling the command\nif flagCompareBase == \"\" && len(args.Params) < 1 {\n    return cmd.UsageError(\"missing branch to compare\")\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Call(args); err != nil {\n    if strings.Contains(err.Error(), \"Usage:\") {\n        fmt.Fprintln(os.Stderr, err)\n        os.Exit(2)\n    }\n}","preventionTips":["Read `hub help <command>` before using rarely used flags","Don't mix flags belonging to different command invocation modes","Wrap invocations in scripts that check exit codes"],"tags":["cli","usage","flag-validation"],"backgroundTag":"command-usage-error","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}