rust-lang/cargo · info · anyhow::Error

couldn't find repository name

Error message

couldn't find repository name

What it means

In `github_fast_path`, the second `pieces.next()` (the repository segment) returned `None` — i.e. the URL is `github.com/<user>` with no repository name. Same swallowed-fast-path semantics as 162/163: logged at `debug!`, never propagated, Cargo continues with the normal fetch.

Source

Thrown at src/sources/git/utils.rs:1656

                rev
            } else {
                debug!("can't use github fast path with `rev = \"{}\"`", rev);
                return Ok(FastPathRev::Indeterminate);
            }
        }
    };

    // This expects GitHub urls in the form `github.com/user/repo` and nothing
    // else
    let mut pieces = url
        .path_segments()
        .ok_or_else(|| anyhow!("no path segments on url"))?;
    let username = pieces
        .next()
        .ok_or_else(|| anyhow!("couldn't find username"))?;
    let repository = pieces
        .next()
        .ok_or_else(|| anyhow!("couldn't find repository name"))?;
    if pieces.next().is_some() {
        anyhow::bail!("too many segments on URL");
    }

    // Trim off the `.git` from the repository, if present, since that's
    // optional for GitHub and won't work when we try to use the API as well.
    let repository = repository.strip_suffix(".git").unwrap_or(repository);

    let url = format!(
        "https://api.github.com/repos/{}/{}/commits/{}",
        username, repository, github_branch_name,
    );
    debug!("attempting GitHub fast path for {}", url);
    let mut request =
        Request::get(url).header(http::header::ACCEPT, "application/vnd.github.3.sha");
    if let Some(local_object) = local_object {
        request = request.header(http::header::IF_NONE_MATCH, &format!("\"{local_object}\""));
    }

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Correct the URL to `https://github.com/<user>/<repo>`.
  2. Treat as non-fatal if you only see it in debug logs — the normal fetch path runs next.

Example fix

# before
foo = { git = "https://github.com/org" }

# after
foo = { git = "https://github.com/org/foo" }
Defensive patterns

Strategy: try-catch

Try / catch

// Same as 162/163: the caller logs and falls back.
match github_fast_path(repo, url, reference, gctx) {
    Ok(r) => r,
    Err(e) => { debug!("failed to check github {:?}", e); /* full fetch */ }
}

Prevention

When it happens

Trigger: A GitHub git URL missing the repo segment, e.g. `https://github.com/org`. Reached only inside the GitHub fast path.

Common situations: Truncated/typo'd URL in a dependency or `[source]` config; copy-paste that dropped the repo; a bad mirror rewrite. The visible symptom is usually a later, real fetch error rather than this message.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/beaec307325387d9.json. Report an issue: GitHub.