{"record":{"id":"b00047f0ec2a2667","repo":"mislav/hub","slug":"error-unknown-subcommand-s","errorCode":null,"errorMessage":"error: Unknown subcommand: %s","messagePattern":"error: Unknown subcommand: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/commands.go","lineNumber":155,"sourceCode":"\tif c.Key != \"\" {\n\t\treturn c.Key\n\t}\n\tusageLine := strings.Split(strings.TrimSpace(c.Usage), \"\\n\")[0]\n\treturn strings.Split(usageLine, \" \")[0]\n}\n\nfunc (c *Command) Runnable() bool {\n\treturn c.Run != nil\n}\n\nfunc (c *Command) lookupSubCommand(args *Args) (runCommand *Command, err error) {\n\tif len(c.subCommands) > 0 && args.HasSubcommand() {\n\t\tsubCommandName := args.FirstParam()\n\t\tif subCommand, ok := c.subCommands[subCommandName]; ok {\n\t\t\trunCommand = subCommand\n\t\t\targs.Params = args.Params[1:]\n\t\t} else {\n\t\t\terr = fmt.Errorf(\"error: Unknown subcommand: %s\", subCommandName)\n\t\t}\n\t} else {\n\t\trunCommand = c\n\t}\n\n\treturn\n}\n","sourceCodeStart":137,"sourceCodeEnd":163,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/commands/commands.go#L137-L163","documentation":"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>\".","triggerScenarios":"Invoking `hub <command> <word>` where <command> declares subCommands, <word> is taken as the subcommand name (args.FirstParam()), and the map lookup fails.","commonSituations":"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.","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."],"exampleFix":"// before\nhub gist lst   // error: Unknown subcommand: lst\n// after\nhub gist list","handlingStrategy":"try-catch","validationCode":"// confirm the subcommand exists before dispatch\nif cmd, ok := parent.subCommands[name]; !ok {\n    fmt.Fprintf(os.Stderr, \"available: %v\\n\", keys(parent.subCommands))\n    os.Exit(2)\n}","typeGuard":null,"tryCatchPattern":"err := command.Call(args)\nif err != nil && strings.HasPrefix(err.Error(), \"error: Unknown subcommand:\") {\n    fmt.Fprintln(os.Stderr, err)\n    os.Exit(1)\n}","preventionTips":["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"],"tags":["cli","subcommand","dispatch"],"backgroundTag":"unknown-subcommand","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}