{"record":{"id":"84c428cdd76e2133","repo":"GitoxideLabs/gitoxide","slug":"at-least-one-chunk","errorCode":null,"errorMessage":"at least one chunk","messagePattern":"at least one chunk","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-chunk/src/file/index.rs","lineNumber":72,"sourceCode":"    ) -> Result<T, Message> {\n        self.chunks\n            .iter()\n            .find_map(|c| (c.kind == kind).then(|| crate::range::into_usize_or_panic(c.offset.clone())))\n            .map(validate)\n            .ok_or_else(make_message(kind))\n    }\n\n    /// Find a chunk of `kind` and return its data slice based on its offset.\n    pub fn data_by_id<'a>(&self, data: &'a [u8], kind: Id) -> Result<&'a [u8], Message> {\n        let offset = self.offset_by_id(kind)?;\n        Ok(&data[crate::range::into_usize(offset)\n            .ok_or_else(|| message(\"The offsets into the file couldn't be represented by usize\"))?])\n    }\n\n    /// Return the end offset of the last chunk, which is the highest offset as well.\n    /// It's definitely available as we have one or more chunks.\n    pub fn highest_offset(&self) -> crate::file::Offset {\n        self.chunks.last().expect(\"at least one chunk\").offset.end\n    }\n}\n\nfn make_message(kind: Id) -> impl FnOnce() -> Message {\n    move || message!(\"Chunk named '{}' was not found in chunk file index\", kind.as_bstr())\n}\n","sourceCodeStart":54,"sourceCodeEnd":79,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-chunk/src/file/index.rs#L54-L79","documentation":"highest_offset() returns the end offset of the last chunk in a chunk file index and asserts via expect that at least one chunk exists. The type's documentation claims one or more chunks are guaranteed (the index requires mandatory chunks at parse time), so an empty chunk list indicates a corrupted or hand-constructed index and panics.","triggerScenarios":"Calling highest_offset() on a gix_chunk::file::Index that was constructed with an empty chunks vector — e.g. via direct/low-level construction bypassing the parser that enforces mandatory chunks.","commonSituations":"Corrupted or truncated multi-pack/commit-graph index files where mandatory chunk entries were dropped; code paths that build Index manually in tests or tooling.","solutions":["Validate the index has chunks before calling highest_offset (e.g. check chunks.is_empty() or use a fallible accessor)","Re-generate or re-read the index file from a valid source; the file is likely corrupt","Use from_bytes/official parse paths which enforce mandatory chunks instead of manual construction","Report the corrupt file scenario if the standard parser can produce an empty chunk list"],"exampleFix":"// before\nlet end = index.highest_offset();\n// after\nif index.chunks().is_empty() {\n    return Err(message(\"chunk file index has no chunks\"));\n}\nlet end = index.highest_offset();","handlingStrategy":"validation","validationCode":"// Guard before using an index whose chunks you did not get from the official parser:\nif index.chunks().is_empty() { return Err(anyhow!(\"chunk index has no chunks\")); }","typeGuard":null,"tryCatchPattern":"// Since highest_offset panics, pre-validate instead:\nlet end = if index.chunks().is_empty() { Default::default() } else { index.highest_offset() };","preventionTips":["Only build chunk indexes via the official parser that enforces mandatory chunks","Validate index files (checksums) before parsing","Re-create corrupted pack/graph index files rather than reading them","Avoid hand-constructing Index values in production code"],"tags":["panic","chunk","index","git"],"backgroundTag":"internal-invariant-violation","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"}