{"record":{"id":"e9fd7156e840e400","repo":"GitoxideLabs/gitoxide","slug":"bug-hunks-are-never-empty","errorCode":null,"errorMessage":"BUG: hunks are never empty","messagePattern":"BUG: hunks are never empty","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-blame/src/file/mod.rs","lineNumber":456,"sourceCode":"}\n\nimpl BlameEntry {\n    /// Create an offset from a portion of the *Blamed File*.\n    fn from_unblamed_hunk(unblamed_hunk: &UnblamedHunk, commit_id: ObjectId) -> Option<Self> {\n        let range_in_source_file = unblamed_hunk.get_range(&commit_id)?;\n\n        Some(Self {\n            start_in_blamed_file: unblamed_hunk.range_in_blamed_file.start,\n            start_in_source_file: range_in_source_file.start,\n            len: force_non_zero(range_in_source_file.len() as u32),\n            commit_id,\n            source_file_name: unblamed_hunk.source_file_name.clone(),\n        })\n    }\n}\n\nfn force_non_zero(n: u32) -> NonZeroU32 {\n    NonZeroU32::new(n).expect(\"BUG: hunks are never empty\")\n}\n\n#[cfg(test)]\nmod tests;\n","sourceCodeStart":438,"sourceCodeEnd":461,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-blame/src/file/mod.rs#L438-L461","documentation":"force_non_zero converts a u32 hunk count/length to NonZeroU32 and panics if the value is 0. The library asserts hunks are never empty (length 0), so a zero-length hunk reaching this function is an invariant violation in the blame computation rather than a user-facing error.","triggerScenarios":"Calling APIs that build FileStats/HunkOutputs (e.g. blame statistics output) where the computed number of hunks or hunk length is 0, violating the 'hunks are never empty' invariant.","commonSituations":"Seen after changes in blame algorithms that can produce zero-length hunks, or when blaming files/commits in edge cases (empty diffs) that were assumed impossible.","solutions":["Check why a zero-length/empty hunk set is being produced and filter or reject empty hunks before conversion","Replace the expect with NonZeroU32::new(n).ok_or(...)? or an explicit error to surface the condition to callers","Verify the blame inputs (file/commit) are valid and produce non-empty hunks","Update gix-blame to a version where zero-length hunks are handled"],"exampleFix":"// before\nfn force_non_zero(n: u32) -> NonZeroU32 {\n    NonZeroU32::new(n).expect(\"BUG: hunks are never empty\")\n}\n// after\nfn force_non_zero(n: u32) -> Option<NonZeroU32> {\n    NonZeroU32::new(n)\n}","handlingStrategy":"validation","validationCode":"// Validate before requesting stats/output:\nif hunk_count == 0 { return Err(anyhow!(\"no hunks produced; cannot build non-zero output\")); }","typeGuard":"fn is_non_zero(n: u32) -> Option<NonZeroU32> { NonZeroU32::new(n) }","tryCatchPattern":null,"preventionTips":["Filter out zero-length hunks before statistics conversion","Assert non-empty hunks upstream where ranges are computed","Treat 'empty blame result' as a normal case, not an error path","Test blame on edge-case inputs (empty diffs, root commits)"],"tags":["panic","invariant","blame","nonzero"],"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-16T04:17:20.429Z"}