zed-industries/zed · error · anyhow::Error

raw diff is missing the path

Error message

raw diff is missing the path

What it means

While parsing 'git diff --raw -z' output, a metadata entry was followed by end-of-input instead of the expected path component — each raw diff entry is a NUL-separated (metadata, path) pair, and the parser hit EOF after reading metadata. This indicates truncated or malformed git output (e.g. a killed process or partial pipe read), so the affected entry is rejected.

Source

Thrown at crates/git/src/commit.rs:192

    pub status: StatusCode,
    pub old_object: Option<CommitDiffObject<'a>>,
    pub new_object: Option<CommitDiffObject<'a>>,
}

/// Parses the output of `git diff --raw --no-abbrev -z`.
pub(crate) fn parse_git_diff_raw(
    content: &str,
) -> impl Iterator<Item = Result<CommitDiffEntry<'_>>> {
    let mut parts = content.split('\0');
    std::iter::from_fn(move || {
        let metadata = parts.next()?;
        if metadata.is_empty() {
            return None;
        }

        let path = match parts.next() {
            Some(path) => path,
            None => return Some(Err(anyhow::anyhow!("raw diff is missing the path"))),
        };
        Some(parse_git_diff_raw_entry(metadata, path))
    })
}

fn parse_git_diff_raw_entry<'a>(metadata: &'a str, path: &'a str) -> Result<CommitDiffEntry<'a>> {
    let mut fields = metadata
        .strip_prefix(':')
        .context("raw diff metadata is missing its ':' prefix")?
        .split_ascii_whitespace();
    let old_mode = fields.next().context("raw diff is missing the old mode")?;
    let new_mode = fields.next().context("raw diff is missing the new mode")?;
    let old_oid = fields
        .next()
        .context("raw diff is missing the old object ID")?;
    let new_oid = fields
        .next()
        .context("raw diff is missing the new object ID")?;

View on GitHub (pinned to f4178619ac)

Solutions

  1. Check that the git process produced complete output (no early termination or partial pipe capture)
  2. Re-run the diff to obtain a complete output stream
  3. Add a regression test with truncated input to keep the parser's malformed-input behavior intentional
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/git/src/commit.rs:192 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/af30defeb4990b29. Report an issue: GitHub.