{"record":{"id":"fab70dad05917c05","repo":"JanDeDobbeleer/oh-my-posh","slug":"invalid-argument-q-for-q","errorCode":null,"errorMessage":"invalid argument %q for %q","messagePattern":"invalid argument %q for %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmdtree/cmdtree.go","lineNumber":529,"sourceCode":"\nfunc RangeArgs(minimum, maximum int) PositionalArgs {\n\treturn func(_ *Command, args []string) error {\n\t\tif len(args) < minimum || len(args) > maximum {\n\t\t\treturn fmt.Errorf(\"accepts between %d and %d arg(s), received %d\", minimum, maximum, len(args))\n\t\t}\n\n\t\treturn nil\n\t}\n}\n\nfunc OnlyValidArgs(cmd *Command, args []string) error {\n\tif len(cmd.ValidArgs) == 0 {\n\t\treturn nil\n\t}\n\n\tfor _, arg := range args {\n\t\tif !contains(cmd.ValidArgs, arg) {\n\t\t\treturn fmt.Errorf(\"invalid argument %q for %q\", arg, cmd.CommandPath())\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc contains(values []string, value string) bool {\n\treturn slices.Contains(values, value)\n}\n","sourceCodeStart":511,"sourceCodeEnd":539,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cmdtree/cmdtree.go#L511-L539","documentation":"OnlyValidArgs validates each positional argument against the command's ValidArgs list (when non-empty). If an argument is not in that whitelist, this error reports the offending argument and the command path. It guards commands like `init` that only accept a fixed set of shell names.","triggerScenarios":"Passing a positional value not listed in cmd.ValidArgs, e.g. `oh-my-posh init zshx` (typo) or an unsupported shell name, to a command using OnlyValidArgs or NoArgsOrOneValidArg.","commonSituations":"Typos in shell names (sh vs zsh, powershell vs pwsh depending on support), using a shell the installed version does not support, or scripts parameterized with a wrong variable value.","solutions":["Correct the argument to one of the valid values listed in the error/docs (bash, zsh, fish, powershell, pwsh, cmd, nu, elvish, xonsh)","Run `oh-my-posh <command> --help` to see the accepted values","Check your shell's actual name (`echo $SHELL`) before substituting it into the command"],"exampleFix":"// before\noh-my-posh init zshx\n// after\noh-my-posh init zsh","handlingStrategy":"validation","validationCode":"const validArgs = ['bash','zsh','fish','powershell','pwsh','cmd','nu','elvish','xonsh'];\nif (arg && !validArgs.includes(arg)) {\n  throw new Error(`invalid argument \"${arg}\"; expected one of: ${validArgs.join(', ')}`);\n}","typeGuard":"function isValidArg(arg, validArgs) { return validArgs.includes(arg); }","tryCatchPattern":"try {\n  runCommand(arg);\n} catch (err) {\n  if (err.message.includes('invalid argument')) {\n    console.error(`'${arg}' not supported; run --help for valid values`);\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Copy valid values from --help instead of typing from memory","Validate dynamic values (e.g. $SHELL) against the supported list before invoking","Keep scripts in sync with the installed CLI version"],"tags":["cli","arguments","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}