JanDeDobbeleer/oh-my-posh · error
invalid argument %q for %q
Error message
invalid argument %q for %q
What it means
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.
Source
Thrown at src/cmdtree/cmdtree.go:529
func RangeArgs(minimum, maximum int) PositionalArgs {
return func(_ *Command, args []string) error {
if len(args) < minimum || len(args) > maximum {
return fmt.Errorf("accepts between %d and %d arg(s), received %d", minimum, maximum, len(args))
}
return nil
}
}
func OnlyValidArgs(cmd *Command, args []string) error {
if len(cmd.ValidArgs) == 0 {
return nil
}
for _, arg := range args {
if !contains(cmd.ValidArgs, arg) {
return fmt.Errorf("invalid argument %q for %q", arg, cmd.CommandPath())
}
}
return nil
}
func contains(values []string, value string) bool {
return slices.Contains(values, value)
}
View on GitHub (pinned to 0976794618)
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
Example fix
// before oh-my-posh init zshx // after oh-my-posh init zsh
Defensive patterns
Strategy: validation
Validate before calling
const validArgs = ['bash','zsh','fish','powershell','pwsh','cmd','nu','elvish','xonsh'];
if (arg && !validArgs.includes(arg)) {
throw new Error(`invalid argument "${arg}"; expected one of: ${validArgs.join(', ')}`);
} Type guard
function isValidArg(arg, validArgs) { return validArgs.includes(arg); } Try / catch
try {
runCommand(arg);
} catch (err) {
if (err.message.includes('invalid argument')) {
console.error(`'${arg}' not supported; run --help for valid values`);
process.exit(1);
}
throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- --data-only and --data-derive contradict each other: one for
- font path must be a valid URL
- required flag(s) "%s" not set
- accepts %d arg(s), received %d
- requires at least %d arg(s), only received %d
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/fab70dad05917c05.
Report an issue: GitHub.