{"record":{"id":"b7eaccc199be6137","repo":"GitoxideLabs/gitoxide","slug":"cannot-use-iter-v2-on-index-of-type","errorCode":null,"errorMessage":"Cannot use iter_v2() on index of type {:?}","messagePattern":"Cannot use iter_v2\\(\\) on index of type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-pack/src/index/access.rs","lineNumber":74,"sourceCode":"        let crcs = self.data[self.offset_crc32_v2()..]\n            .as_chunks::<N32_SIZE>()\n            .0\n            .iter()\n            .take(self.num_objects as usize);\n        let offsets = self.data[self.offset_pack_offset_v2()..]\n            .as_chunks::<N32_SIZE>()\n            .0\n            .iter()\n            .take(self.num_objects as usize);\n        assert_eq!(oids.len(), crcs.len());\n        assert_eq!(crcs.len(), offsets.len());\n        match self.version {\n            index::Version::V2 => izip!(oids, crcs, offsets).map(move |(oid, crc32, ofs32)| Entry {\n                oid: gix_hash::ObjectId::from_bytes_or_panic(oid),\n                pack_offset: self.pack_offset_from_offset_v2(ofs32, pack64_offset),\n                crc32: Some(crate::read_u32(crc32)),\n            }),\n            _ => panic!(\"Cannot use iter_v2() on index of type {:?}\", self.version),\n        }\n    }\n\n    /// Returns the object hash at the given index in our list of (sorted) sha1 hashes.\n    /// The index ranges from 0 to `self.num_objects()`\n    ///\n    /// # Panics\n    ///\n    /// If `index` is out of bounds.\n    pub fn oid_at_index(&self, index: EntryIndex) -> &gix_hash::oid {\n        let index = index as usize;\n        let start = match self.version {\n            index::Version::V2 => V2_HEADER_SIZE + index * self.hash_len,\n            index::Version::V1 => V1_HEADER_SIZE + index * (N32_SIZE + self.hash_len) + N32_SIZE,\n        };\n        gix_hash::oid::from_bytes_unchecked(&self.data[start..][..self.hash_len])\n    }\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-pack/src/index/access.rs#L56-L92","documentation":"`gix_pack::index::File::iter_v2()` only works on pack index version V2. On any other version (i.e. V1) the match arm `_ => panic!` fires. It mirrors the iter_v1 panic: version-specific accessors must only be called on matching index versions.","triggerScenarios":"Calling `index_file.iter_v2()` on a `Version::V1` index; assuming all .idx files are v2 (git's modern default) and calling the v2 accessor directly.","commonSituations":"Reading old repositories cloned before git 1.6 that still carry v1 indexes; fixtures or test repos with v1 packs; custom tooling that skips the `iter()` dispatcher.","solutions":["Call `index_file.iter()` which handles both versions automatically","Guard with `if index_file.version == index::Version::V2` before calling `iter_v2()`","Use `iter_v1()` for V1 indexes","Rewrite the pack index with `git index-pack` to upgrade to v2"],"exampleFix":"// before\nlet entries = index_file.iter_v2(); // panics on v1 indexes\n// after\nlet entries = match index_file.version {\n    gix_pack::index::Version::V2 => index_file.iter_v2().collect(),\n    _ => index_file.iter_v1().collect(),\n};","handlingStrategy":"validation","validationCode":"if index_file.version == gix_pack::index::Version::V2 {\n    let entries: Vec<_> = index_file.iter_v2().collect();\n} else {\n    let entries: Vec<_> = index_file.iter().collect();\n}","typeGuard":"fn supports_v2(index: &gix_pack::index::File) -> bool {\n    index.version == gix_pack::index::Version::V2\n}","tryCatchPattern":null,"preventionTips":["Default to iter() unless version-specific behavior is required","Check version once at load time and branch from there","Regenerate legacy v1 indexes with git index-pack"],"tags":["rust","panic","pack","index","version"],"backgroundTag":"unsupported-operation","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}