Morganamilo/paru · error
option expects a value
Error message
option {} expects a value What it means
This is a command-line argument validation failure inside handle_arg (src/command_line.rs), the per-argument dispatcher invoked by parse_arg while building the Config from argv. It fires when the parser matched an option that is registered by takes_value() as TakesValue::Required (an option whose value is not optional) but no value could be attached to it: the option was the last token on the command line, or it appeared in a position where the parser explicitly passes value=None (such as the non-forced handle_arg call for bare arguments). Because there is no sane default for a mandatory option's payload, handle_arg bails out of the whole parse instead of continuing, aborting startup.
Solutions
- Supply the value: `--sortby name` or `--sortby=name`
- Check scripts for empty variables used as option values
- Consult `--help` to see which options require a value
Example fix
// before args: ["--sortby"] // after args: ["--sortby", "name"] // or "--sortby=name"
Defensive patterns
Strategy: validation
Validate before calling
const REQUIRES_VALUE: &[&str] = &["sortby", "searchby", "limit", "completioninterval", "sortby"];
function validate_args(args: string[]): string | null {
for (let i = 0; i < args.length; i++) {
const name = args[i].split('=')[0].replace(/^--?/, '');
if (REQUIRES_VALUE.includes(name) && !args[i].includes('=') && i + 1 >= args.length)
return `--${name} expects a value`;
}
return null;
} Try / catch
match cli::parse(&args) {
Err(e) if e.to_string().contains("expects a value") => {
eprintln!("{}; usage: --option value or --option=value", e);
std::process::exit(2);
}
Err(e) => return Err(e),
Ok(cmd) => cmd.run(),
} Prevention
- Always pass the value in the same token using `=` syntax: `--limit=5`
- Validate CLI args in shell scripts before exec
- Check `--help` for which options take values
When it happens
Trigger: Passing a value-requiring flag like `--sortby`, `--limit`, `--completioninterval`, or `--searchby` without an `=value` or a following argument, e.g. `--sortby` alone, or as the last token on the command line.
Common situations: Users typing a flag without its value or forgetting the `=`; shell scripts dropping an empty variable (`--limit "$EMPTY"`); truncated commands in CI pipelines.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- unknown option
- option does not allow a value
- unknown option
- option must be a number
- no targets specified (use -h for help)
AI-assisted analysis of Morganamilo/paru@9ac3578807 (2026-09-12).
Data as JSON: /api/errors/c1214af5394097d0.
Report an issue: GitHub.
Appendix: source
Thrown at src/command_line.rs:134
}
self.handle_arg(arg, None, op_count, false)?;
}
Ok(false)
} else {
self.targets.push(arg.to_string());
Ok(false)
}
}
fn handle_arg(
&mut self,
arg: Arg,
mut value: Option<&str>,
op_count: &mut u8,
forced: bool,
) -> Result<()> {
match takes_value(arg) {
TakesValue::Required if value.is_none() => bail!(tr!("option {} expects a value", arg)),
_ => (),
}
if takes_value(arg) != TakesValue::Required && !forced {
value = None;
}
if arg.is_pacman_global() {
self.globals.args.push(crate::args::Arg {
key: arg.arg(),
value: value.map(|s| s.to_string()),
});
self.args.args.push(crate::args::Arg {
key: arg.arg(),
value: value.map(|s| s.to_string()),
});
}
View on GitHub (pinned to 9ac3578807)