GitoxideLabs/gitoxide · warning

prior validation

Error message

prior validation

What it means

A Rust `expect()` panic in the loose-ref `parse` helper (gix-ref/store/file/loose/reference/decode.rs), called when building a `Reference` via `try_from_path`. `hex_hash` already validated that the input starts with a correctly sized run of hex digits for `object_hash`, so `ObjectId::from_hex` must succeed; `expect("prior validation")` documents that invariant. It panics only if `hex_hash` accepted hex digits whose count differs from what `from_hex` requires — a hash-kind/length mismatch between the validation step and the decoder.

Solutions

  1. Pass the repository's actual `object_hash` kind to `Reference::try_from_path` rather than a hard-coded kind.
  2. Verify the loose ref file contents (a direct ref must be exactly one valid 40/64-char hex id) and repair it (`git symbolic-ref`/`git update-ref`).
  3. Run `git fsck` to identify and fix corrupted refs.
  4. Report upstream with the ref file bytes if kinds match and it still panics.

Example fix

// before
Reference::try_from_path(name, contents, gix_hash::Kind::Sha1)? // repo is Sha256 -> panic
// after
Reference::try_from_path(name, contents, repo.object_hash())?
Defensive patterns

Strategy: validation

Validate before calling

// use the repo's real hash kind when decoding loose refs
let kind = repo.object_hash();
Reference::try_from_path(name, contents, kind).map_err(|e| ...)?;

Prevention

When it happens

Trigger: Parsing a loose ref file whose leading hex id length matches `hex_hash`'s acceptance but not `ObjectId::from_hex`'s expectation — e.g. the caller supplied a `gix_hash::Kind` different from the one the ref file was written with, or `hex_hash`'s validation window is inconsistent with the kind.

Common situations: SHA-256 repositories parsed with SHA-1 kind (or vice versa); corrupted loose ref files with truncated/overlong hex ids; hand-edited `.git/refs/**` files.

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/347b80e7bc724ea9. Report an issue: GitHub.

Appendix: source

Thrown at gix-ref/src/store/file/loose/reference/decode.rs:92

/// If neither reference form can be parsed, an error is returned.
fn parse(mut i: &[u8], object_hash: gix_hash::Kind) -> Result<MaybeUnsafeState, ()> {
    if let Some(rest) = i.strip_prefix(b"ref: ") {
        i = rest;
        while i.first() == Some(&b' ') {
            i = &i[1..];
        }
        let path_end = i
            .iter()
            .position(|b| *b == b'\0' || *b == b'\r' || *b == b'\n')
            .unwrap_or(i.len());
        let path = i[..path_end].into();
        Ok(MaybeUnsafeState::UnvalidatedPath(path))
    } else {
        let hex = hex_hash(&mut i, object_hash)?;
        if i.first().is_some_and(u8::is_ascii_hexdigit) {
            return Err(());
        }
        Ok(MaybeUnsafeState::Id(ObjectId::from_hex(hex).expect("prior validation")))
    }
}

View on GitHub (pinned to e73179060b)