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

  1. Correct the argument to one of the valid values listed in the error/docs (bash, zsh, fish, powershell, pwsh, cmd, nu, elvish, xonsh)
  2. Run `oh-my-posh <command> --help` to see the accepted values
  3. 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

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


AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31). Data as JSON: /api/errors/fab70dad05917c05. Report an issue: GitHub.