{"record":{"id":"d22b4763a0001b8f","repo":"JanDeDobbeleer/oh-my-posh","slug":"unknown-command-q-for-q","errorCode":null,"errorMessage":"unknown command %q for %q","messagePattern":"unknown command %q for %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmdtree/cmdtree.go","lineNumber":245,"sourceCode":"\n\treturn cmd.execute(remaining)\n}\n\n// route walks the command tree: at each level the first token that is not a\n// flag (accounting for flags that consume a value) addresses a child.\nfunc (c *Command) route(args []string) (*Command, []string, error) {\n\tcurrent := c\n\n\tfor {\n\t\tname, ok := firstPositional(current, args)\n\t\tif !ok {\n\t\t\treturn current, args, nil\n\t\t}\n\n\t\tchild := current.findChild(name)\n\t\tif child == nil {\n\t\t\tif current == c && len(current.commands) > 0 {\n\t\t\t\treturn nil, nil, fmt.Errorf(\"unknown command %q for %q\", name, c.CommandPath())\n\t\t\t}\n\n\t\t\treturn current, args, nil\n\t\t}\n\n\t\targs = removeFirst(args, name)\n\t\tcurrent = child\n\t}\n}\n\n// firstPositional finds the first argument that cannot be a flag or a flag\n// value at this command level.\nfunc firstPositional(c *Command, args []string) (string, bool) {\n\tflags := c.mergedFlags()\n\n\tfor i := 0; i < len(args); i++ {\n\t\targ := args[i]\n","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cmdtree/cmdtree.go#L227-L263","documentation":"During Execute, route walks the command tree matching positional tokens to child commands. If the first positional token matches no child (and no alias) of the root command, and the root has subcommands, routing fails with this error before any command runs. It mirrors cobra's message so scripts see familiar output.","triggerScenarios":"Execute() (or SetArgs + Execute) called with os.Args whose first non-flag token is not a registered child name/alias of the root, while the root has children: e.g. 'omp foo --bar' with no 'foo' command.","commonSituations":"Typos in the subcommand name; invoking a command that exists in a newer/older binary version; running a script written for another tool; passing a file path as the first argument to a command that doesn't take one.","solutions":["Run 'omp --help' (or the tool's help) and use an exact subcommand name from Available Commands.","Check the binary version - the command may have been renamed/added; upgrade or use the old name.","Fix typos in scripts/aliases invoking the command.","If a value (not a subcommand) was intended as the first argument, restructure the invocation or use -- before it so routing doesn't treat it as a command."],"exampleFix":"// before\nargs := []string{\"inti\", \"shell\"} // unknown command \"inti\" for \"oh-my-posh\"\n// after\nargs := []string{\"init\", \"shell\"}","handlingStrategy":"try-catch","validationCode":"func validateSubcommand(root string, valid []string, args []string) error {\n    if len(args) > 0 && !slices.Contains(valid, args[0]) {\n        return fmt.Errorf(\"%q is not a valid subcommand of %s; valid: %v\", args[0], root, valid)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Execute(); err != nil {\n    if strings.HasPrefix(err.Error(), \"unknown command\") {\n        fmt.Fprintf(os.Stderr, \"Error: %v\\nTip: run '<root> --help' to list available commands.\\n\", err)\n        os.Exit(1)\n    }\n    return err\n}","preventionTips":["Run '<root> --help' to confirm exact subcommand names and aliases before scripting.","Pin/verify the binary version in scripts; subcommands change across releases.","Tab-complete subcommand names interactively instead of typing from memory.","Use -- before arbitrary values so routing never mistakes them for subcommands."],"tags":["cli","cmdtree","command-routing"],"backgroundTag":"unknown-command","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}