nikivdev/code · error

unknown `f pr preview` option: {token}

Error message

unknown `f pr preview` option: {token}

What it means

The `f pr preview` argument parser only accepts --json, --mode, --base, and --path. Any other token reaches the catch-all arm of the match and produces this error naming the unrecognized token.

Source

Thrown at src/pr_preview.rs:304

                };
                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,
        mode,
        json,
    }))
}

fn parse_mode_arg(value: &str) -> Result<PrPreviewModeArg> {
    match value.trim().to_ascii_lowercase().as_str() {
        "draft" => Ok(PrPreviewModeArg::Draft),
        "feedback" => Ok(PrPreviewModeArg::Feedback),
        other => bail!("unsupported `f pr preview --mode` value: {other}"),
    }
}

View on GitHub (pinned to a747e741ae)

Solutions

  1. Use only supported flags: --json, --mode, --base, --path
  2. Check spelling of the flag (the offending token is named in the message)
  3. Run the command without extra positional arguments

Example fix

// before
f pr preview --mde draft
// after
f pr preview --mode draft
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED: [&str; 4] = ["--json", "--mode", "--base", "--path"];
for a in &args {
    if a.starts_with("--") && !ALLOWED.contains(&a.as_str()) {
        anyhow::bail!("unsupported flag: {a}");
    }
}

Try / catch

if let Err(e) = run_pr_preview(cmd) {
    if e.to_string().starts_with("unknown `f pr preview` option") {
        eprintln!("Supported flags: --json --mode --base --path");
    }
}

Prevention

When it happens

Trigger: Passing an unsupported flag such as `f pr preview --help-me`, a misspelled flag like `--mod`, or a stray positional argument.

Common situations: Typo'd flags; options valid for other `f` subcommands but not preview; leftover positional args from a different command's syntax.

Related errors


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