zed-industries/zed · error

too many arguments

Error message

too many arguments

What it means

Bailed by the git_log_context helper binary's main when it receives more than two positional arguments. The helper accepts exactly `<worktree-path> <query-path>` and no flags; after the first two arguments, any third triggers the usage print plus this error.

Source

Thrown at crates/edit_prediction_context/src/git_log_context.rs:145

fn run() -> Result<()> {
    let mut arguments = env::args_os();
    let program_name = arguments
        .next()
        .and_then(|path| PathBuf::from(path).file_name().map(|name| name.to_owned()))
        .and_then(|name| name.into_string().ok())
        .unwrap_or_else(|| "git_log_context".to_string());

    let worktree_dir = arguments.next().ok_or_else(|| {
        print_usage(&program_name);
        anyhow!("missing worktree path")
    })?;
    let query_path = arguments.next().ok_or_else(|| {
        print_usage(&program_name);
        anyhow!("missing query path")
    })?;
    if arguments.next().is_some() {
        print_usage(&program_name);
        bail!("too many arguments");
    }

    let worktree_dir = PathBuf::from(worktree_dir);
    let query_path = normalize_query_path(&worktree_dir, &PathBuf::from(query_path));
    let index = futures::executor::block_on(build_git_log_index(&worktree_dir))?;

    for (path, count) in index.get_related_with_counts(&query_path, 10) {
        println!("{count}\t{}", path.display());
    }

    Ok(())
}

#[allow(dead_code)]
fn print_usage(program_name: &str) {
    eprintln!("Usage: {program_name} <worktree-path> <query-path>");
}

View on GitHub (pinned to f4178619ac)

Solutions

  1. Pass exactly two arguments: the worktree path and the query path
  2. Quote each path as a single shell argument so spaces don't split it
  3. Remove any options — this helper takes none

Example fix

# before
git-log-context /repo 'src/a b.rs' extra

# after
git-log-context /repo 'src/a b.rs'
Defensive patterns

Strategy: validation

Validate before calling

if argv.len() > 2 {
    // reject before spawning: helper takes exactly <worktree> <query-path>
}

Try / catch

Validate the argument count client-side and fail with the usage line before spawning; a spawn that fails this way wastes a process round-trip.

Prevention

When it happens

Trigger: Invoking the helper with an extra flag or path, or shell word-splitting turning an unquoted path with spaces into multiple arguments.

Common situations: Passing `-n 10` style flags that belong to other tools; unquoted variables in scripts; leftover placeholder arguments.

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 zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/82446a7cc5e16411. Report an issue: GitHub.