{"record":{"id":"f5da14251c3dd4be","repo":"GitoxideLabs/gitoxide","slug":"next","errorCode":null,"errorMessage":"next","messagePattern":"next","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-ref/src/store/packed/transaction.rs","lineNumber":181,"sourceCode":"        let mut file = self.lock.expect(\"a write lock for applying changes\");\n        let refs_sorted: Box<dyn Iterator<Item = Result<packed::Reference<'_>, packed::iter::Error>>> =\n            match self.buffer.as_ref() {\n                Some(buffer) => Box::new(buffer.iter()?),\n                None => Box::new(std::iter::empty()),\n            };\n\n        let mut refs_sorted = refs_sorted.peekable();\n\n        edits.sort_by(|l, r| l.inner.name.as_bstr().cmp(r.inner.name.as_bstr()));\n        let mut peekable_sorted_edits = edits.iter().peekable();\n\n        file.with_mut(|f| f.write_all(HEADER_LINE))?;\n\n        let mut num_written_lines = 0;\n        loop {\n            match (refs_sorted.peek(), peekable_sorted_edits.peek()) {\n                (Some(Err(_)), _) => {\n                    let err = refs_sorted.next().expect(\"next\").expect_err(\"err\");\n                    return Err(commit::Error::Iteration(err));\n                }\n                (None, None) => {\n                    break;\n                }\n                (Some(Ok(_)), None) => {\n                    let pref = refs_sorted.next().expect(\"next\").expect(\"no err\");\n                    num_written_lines += 1;\n                    file.with_mut(|out| write_packed_ref(out, pref))?;\n                }\n                (Some(Ok(pref)), Some(edit)) => {\n                    use std::cmp::Ordering::*;\n                    match pref.name.as_bstr().cmp(edit.inner.name.as_bstr()) {\n                        Less => {\n                            let pref = refs_sorted.next().expect(\"next\").expect(\"valid\");\n                            num_written_lines += 1;\n                            file.with_mut(|out| write_packed_ref(out, pref))?;\n                        }","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-ref/src/store/packed/transaction.rs#L163-L199","documentation":"Panic raised by `refs_sorted.next().expect(\"next\")` in the packed-refs transaction commit loop. `peek()` had just returned `Some(Err(_))`, so `next()` must also return `Some`; if not, the peekable iterator's state contradicts itself — an internal invariant. The immediate `expect_err` converts the item into the iteration error reported to the caller.","triggerScenarios":"Reaching the `(Some(Err(_)), _)` match arm during `commit()` where the peeked iteration error disappears on `next()` — logically impossible with `std::iter::Peekable`; only a bug (e.g. misuse of the iterator between peek and next) could trigger it.","commonSituations":"Not user-reachable under correct library use; it surfaces only when a packed-refs iteration error occurs (corrupt file) AND an internal iterator invariant is already broken.","solutions":["Treat any occurrence as a gitoxide bug and report it with the stack trace and packed-refs contents.","If the underlying cause is an iteration error, repair the corrupt packed-refs file.","Use a gix-ref version without the faulty peek/next interplay."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// pre-validate packed-refs parses cleanly to avoid the iteration-error path\nfor r in buffer.iter() { r.map_err(|e| format!(\"corrupt packed-refs: {e}\"))?; }","typeGuard":null,"tryCatchPattern":"// wrap the transaction in catch_unwind at a boundary if input is untrusted\nlet res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| tx.commit()));","preventionTips":["Validate the packed-refs file before running packed transactions on it.","Report any panic in the commit loop as a gitoxide bug.","Keep gix-ref updated to benefit from iterator-handling fixes."],"tags":["panic","iterator","internal-invariant","packed-refs"],"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"}