{"record":{"id":"66e09d11d8740585","repo":"GitoxideLabs/gitoxide","slug":"cannot-use-iter-v1-on-index-of-type","errorCode":null,"errorMessage":"Cannot use iter_v1() on index of type {:?}","messagePattern":"Cannot use iter_v1\\(\\) on index of type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-pack/src/index/access.rs","lineNumber":47,"sourceCode":"/// Iteration and access\nimpl<T> index::File<T>\nwhere\n    T: crate::FileData,\n{\n    fn iter_v1(&self) -> impl Iterator<Item = Entry> + '_ {\n        match self.version {\n            index::Version::V1 => self.data[V1_HEADER_SIZE..]\n                .chunks_exact(N32_SIZE + self.hash_len)\n                .take(self.num_objects as usize)\n                .map(|c| {\n                    let (ofs, oid) = c.split_at(N32_SIZE);\n                    Entry {\n                        oid: gix_hash::ObjectId::from_bytes_or_panic(oid),\n                        pack_offset: u64::from(crate::read_u32(ofs)),\n                        crc32: None,\n                    }\n                }),\n            _ => panic!(\"Cannot use iter_v1() on index of type {:?}\", self.version),\n        }\n    }\n\n    fn iter_v2(&self) -> impl Iterator<Item = Entry> + '_ {\n        let pack64_offset = self.offset_pack_offset64_v2();\n        let oids = self.data[V2_HEADER_SIZE..]\n            .chunks_exact(self.hash_len)\n            .take(self.num_objects as usize);\n        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);","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-pack/src/index/access.rs#L29-L65","documentation":"`gix_pack::index::File::iter_v1()` only works on pack index version V1 (.idx v1). When called on any other version the match falls through to a `_ => panic!` arm. The public `iter()` wrapper normally dispatches by version, so hitting this panic means the version dispatch was bypassed or the caller assumed the wrong version.","triggerScenarios":"Calling `index_file.iter_v1()` directly on a `gix_pack::index::File` whose `version` is `Version::V2`; hard-coding v1 access after loading a v2 index.","commonSituations":"Working with mixed repositories where some packs have v1 and others v2 indexes; code written against old repos then run on modern ones (git defaults to v2); writing custom pack iteration logic.","solutions":["Use `index_file.iter()` instead, which dispatches to the correct version","Check `index_file.version` and only call `iter_v1()` when it equals `Version::V1`","Use `iter_v2()` for `Version::V2` indexes","Regenerate the index if you specifically need v1 semantics"],"exampleFix":"// before\nlet entries = index_file.iter_v1(); // panics on v2 indexes\n// after\nlet entries = index_file.iter(); // dispatches correctly by version","handlingStrategy":"validation","validationCode":"if index_file.version == gix_pack::index::Version::V1 {\n    let entries: Vec<_> = index_file.iter_v1().collect();\n} else {\n    let entries: Vec<_> = index_file.iter().collect();\n}","typeGuard":"fn supports_v1(index: &gix_pack::index::File) -> bool {\n    index.version == gix_pack::index::Version::V1\n}","tryCatchPattern":null,"preventionTips":["Always prefer the version-agnostic iter()","Log/assert index version when loading packs in mixed-version repos","Normalize repo indexes to v2 so version-specific calls are safe"],"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"}