GitoxideLabs/gitoxide · error

this one only happens on iteration creation

Error message

this one only happens on iteration creation

What it means

An `unreachable!()` panic in `convert_packed` within gix-ref's overlay ref iterator. When converting packed-refs iteration results, only per-line `InvalidLine`-style errors are expected; the `Header` error variant is supposed to surface exclusively when the packed-refs iterator is created (at buffer open), never mid-iteration. The panic fires if a header error is emitted during iteration.

Solutions

  1. Repair or regenerate the packed-refs file: run `git pack-refs --all` (after checking `git fsck`) or delete `.git/packed-refs` to fall back to loose refs
  2. Restore the repository from a clean clone if refs data is corrupted
  3. Upgrade gix / gix-ref so header errors are consistently rejected at iterator creation, and report the file content that triggered the panic upstream
Defensive patterns

Strategy: validation

Validate before calling

fn packed_refs_look_sane(git_dir: &std::path::Path) -> bool {
    match std::fs::read(git_dir.join("packed-refs")) {
        Ok(bytes) => bytes.is_empty() || bytes.starts_with(b"# pack-refs") || bytes.starts_with(b"#"),
        Err(_) => true, // absent file is fine
    }
}

Try / catch

std::panic::catch_unwind(|| refs.all().collect::<Vec<_>>())
    .map_err(|_| "packed-refs corrupted mid-iteration; regenerate with git pack-refs")?

Prevention

When it happens

Trigger: Iterating all refs of a repository (overlay of loose + packed refs, e.g. `repo.references()` or `gix ref list`) when the packed-refs file's header section turns out to be malformed but was not rejected at open time — e.g. a corrupted `packed-refs` file (truncated header, bad peeled-line placement) or a gix-ref version mismatch between open-time and iteration-time validation.

Common situations: Repositories with manually edited or partially written `packed-refs` files (interrupted `git pack-refs`, disk issues, sharing `.git` across tools/OSes), or older gix versions with inconsistent packed-refs header validation.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of GitoxideLabs/gitoxide@e73179060b (2026-09-08). Data as JSON: /api/errors/29f0a8c692547b43. Report an issue: GitHub.

Appendix: source

Thrown at gix-ref/src/store/file/overlay_iter.rs:82

        }
    }

    fn convert_packed(
        &mut self,
        packed: Result<packed::Reference<'p>, packed::iter::Error>,
    ) -> Result<Reference, Error> {
        packed
            .map(Into::into)
            .map(|r| self.strip_namespace(r))
            .map_err(|err| match err {
                packed::iter::Error::Reference {
                    invalid_line,
                    line_number,
                } => Error::PackedReference {
                    invalid_line,
                    line_number,
                },
                packed::iter::Error::Header { .. } => unreachable!("this one only happens on iteration creation"),
            })
    }

    fn convert_loose(&mut self, res: std::io::Result<(PathBuf, FullName)>) -> Result<Reference, Error> {
        let buf = &mut self.buf;
        let git_dir = self.git_dir;
        let common_dir = self.common_dir;
        let (refpath, name) = res.map_err(Error::Traversal)?;
        std::fs::File::open(&refpath)
            .and_then(|mut f| {
                buf.clear();
                f.read_to_end(buf)
            })
            .map_err(|err| Error::ReadFileContents {
                source: err,
                path: refpath.to_owned(),
            })?;
        loose::Reference::try_from_path(name, buf, self.object_hash)

View on GitHub (pinned to e73179060b)