JanDeDobbeleer/oh-my-posh · error
accepts between %d and %d arg(s), received %d
Error message
accepts between %d and %d arg(s), received %d
What it means
RangeArgs(minimum, maximum) validates that positional argument count falls within an inclusive range. This error is returned when len(args) is below minimum or above maximum. It gives commands flexibility (0..1 args, 1..2 args) while still bounding accepted input.
Source
Thrown at src/cmdtree/cmdtree.go:515
return nil
}
}
func MinimumNArgs(n int) PositionalArgs {
return func(_ *Command, args []string) error {
if len(args) < n {
return fmt.Errorf("requires at least %d arg(s), only received %d", n, len(args))
}
return nil
}
}
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 nilView on GitHub (pinned to 0976794618)
Solutions
- Check the command's documented arg range via --help and adjust the count
- Quote multi-word arguments so they count as a single positional
- Move optional extras into flags instead of positional arguments
Example fix
// before oh-my-posh get shell extra1 extra2 // after oh-my-posh get shell
Defensive patterns
Strategy: validation
Validate before calling
const min = 1, max = 2;
const n = process.argv.length - 2;
if (n < min || n > max) {
throw new Error(`accepts between ${min} and ${max} arg(s), received ${n}`);
} Type guard
function hasArgRange(args, min, max) { return Array.isArray(args) && args.length >= min && args.length <= max; } Try / catch
try {
runCommand(args);
} catch (err) {
if (err.message.includes('accepts between')) {
printUsageAndExit();
}
throw err;
} Prevention
- Quote multi-word arguments to keep the count correct
- Consult --help for the accepted range
- Replace optional extras with flags
When it happens
Trigger: Calling a command registered with RangeArgs(min, max) with an argument count outside the inclusive range, e.g. passing three positionals to a command that accepts between one and two.
Common situations: Pasting multi-word strings without quotes so one logical argument becomes several positional args, or appending extra tokens like a theme name where none is accepted.
Related errors
- accepts %d arg(s), received %d
- requires at least %d arg(s), only received %d
- invalid argument %q for %q
- invalid export format
- --data-only and --data-derive contradict each other: one for
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/2d063181e69fd30e.
Report an issue: GitHub.