Jguer/yay · error

invalid option

Error message

invalid option '%s'

What it means

addParam in pkg/settings/parser/parser.go validates each option string against isArg before processing. If the option is not a recognized flag/operation of the parser, it returns 'invalid option '%s''. This is the parser's generic rejection of unknown CLI flags.

Solutions

  1. Check the flag spelling against the tool's documented options (and pacman's for pacman-style flags).
  2. Run with --help or the man page to list valid options for this version.
  3. Remove the unsupported flag; if it came from an alias or script, fix the alias/script definition.
  4. Upgrade or downgrade the tool if the flag exists in another version.

Example fix

// before
yay -Ss firefox --noconfirmr   # typo'd flag
// after
yay -Ss firefox --noconfirm
Defensive patterns

Strategy: validation

Validate before calling

// Validate options against the parser's known set before calling AddArg
for _, opt := range myFlags {
    if !parser.IsArg(opt) { // if exported; otherwise keep a local allowlist
        return fmt.Errorf("unsupported option %q", opt)
    }
}

Try / catch

if err := args.AddArg(opt); err != nil {
    if strings.Contains(err.Error(), "invalid option") {
        return usageError(fmt.Sprintf("unknown flag %s — see --help", opt))
    }
    return err
}

Prevention

When it happens

Trigger: AddArg, parseShortOption or parseLongOption encounters an option string not present in the parser's known-argument table; e.g. passing '-Z' or '--nonsense' to the Arguments parser.

Common situations: Typos in flags (-Q vs -q); flags supported by pacman but not by this tool/version; flags removed or renamed in a version change; forwarding arbitrary user flags into the parser programmatically.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of Jguer/yay@328f4b4939 (2026-09-07). Data as JSON: /api/errors/1cd82bf03975a95d. Report an issue: GitHub.

Appendix: source

Thrown at pkg/settings/parser/parser.go:173

		return true
	default:
		return false
	}
}

func (a *Arguments) addOP(op string) error {
	if a.Op != "" {
		return errors.New(gotext.Get("only one operation may be used at a time"))
	}

	a.Op = op

	return nil
}

func (a *Arguments) addParam(option, arg string) error {
	if !isArg(option) {
		return errors.New(gotext.Get("invalid option '%s'", option))
	}

	if isOp(option) {
		return a.addOP(option)
	}

	a.CreateOrAppendOption(option, strings.Split(arg, ",")...)

	if isGlobal(option) {
		a.Options[option].Global = true
	}

	return nil
}

func (a *Arguments) AddArg(options ...string) error {
	for _, option := range options {
		err := a.addParam(option, "")

View on GitHub (pinned to 328f4b4939)