nikivdev/code · error

`f pr preview --base` requires a value

Error message

`f pr preview --base` requires a value

What it means

The `--base` flag of `f pr preview` requires a value specifying the base branch/ref. This error is thrown when --base appears with no following argument.

Source

Thrown at src/pr_preview.rs:292

    let mut json = opts.json;

    let mut index = 1;
    while index < args.len() {
        match args[index].as_str() {
            "--json" => {
                json = true;
                index += 1;
            }
            "--mode" => {
                let Some(value) = args.get(index + 1) else {
                    bail!("`f pr preview --mode` requires a value");
                };
                mode = parse_mode_arg(value)?;
                index += 2;
            }
            "--base" => {
                let Some(value) = args.get(index + 1) else {
                    bail!("`f pr preview --base` requires a value");
                };
                requested_base = value.clone();
                index += 2;
            }
            "--path" => {
                let Some(value) = args.get(index + 1) else {
                    bail!("`f pr preview --path` requires a value");
                };
                repo_path = Some(PathBuf::from(value));
                index += 2;
            }
            token => bail!("unknown `f pr preview` option: {token}"),
        }
    }

    Ok(Some(PrPreviewCommand {
        repo_path,
        requested_base,

View on GitHub (pinned to a747e741ae)

Solutions

  1. Supply a base ref: `f pr preview --base main`
  2. Check that any variable holding the branch name is non-empty in scripts
  3. Quote the branch value if it contains special characters

Example fix

// before
f pr preview --base
// after
f pr preview --base main
Defensive patterns

Strategy: validation

Validate before calling

if args.iter().any(|a| a == "--base") {
    let i = args.iter().position(|a| a == "--base").unwrap();
    if args.get(i + 1).is_none() { anyhow::bail!("--base needs a branch/ref"); }
}

Try / catch

if let Err(e) = run_pr_preview(cmd) {
    if e.to_string().contains("--base`) requires a value") {
        eprintln!("Usage: f pr preview --base <branch>");
    }
}

Prevention

When it happens

Trigger: Running `f pr preview --base` as the final argument, leaving requested_base unset with nothing to consume.

Common situations: Forgotten branch name after --base; scripts where the branch variable expanded to empty; copy-paste dropping the value.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/f69837abbd6cb231. Report an issue: GitHub.