{"record":{"id":"4adce18c38f32a07","repo":"GitoxideLabs/gitoxide","slug":"we-are-called-from-a-valid-ref","errorCode":null,"errorMessage":"we are called from a valid ref","messagePattern":"we are called from a valid ref","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-ref/src/store/file/loose/reference/logiter.rs","lineNumber":9,"sourceCode":"use crate::store_impl::{\n    file,\n    file::{log, loose, loose::Reference},\n};\n\npub(crate) fn must_be_io_err(err: loose::reflog::Error) -> std::io::Error {\n    match err {\n        loose::reflog::Error::Io(err) => err,\n        loose::reflog::Error::RefnameValidation(_) => unreachable!(\"we are called from a valid ref\"),\n    }\n}\n\nimpl Reference {\n    /// Returns true if a reflog exists in the given `store`.\n    ///\n    /// Please note that this method shouldn't be used to check if a log exists before trying to read it, but instead\n    /// is meant to be the fastest possible way to determine if a log exists or not.\n    /// If the caller needs to know if it's readable, try to read the log instead with a reverse or forward iterator.\n    pub fn log_exists(&self, store: &file::Store) -> bool {\n        store\n            .reflog_exists(self.name.as_ref())\n            .expect(\"name conversion infallible\")\n    }\n    /// Return a reflog reverse iterator for this ref, reading chunks from the back into the fixed buffer `buf`, in the given `store`.\n    ///\n    /// The iterator will traverse log entries from most recent to oldest, reading the underlying file in chunks from the back.\n    /// Return `Ok(None)` if no reflog exists.","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-ref/src/store/file/loose/reference/logiter.rs#L1-L27","documentation":"An `unreachable!()` panic in `must_be_io_err`, an internal gix-ref helper that downcasts a loose reflog error to `std::io::Error`. The helper is only ever invoked from code paths operating on an already-validated ref name, so a `RefnameValidation` error variant is considered impossible; the panic fires if validation-style errors leak into those call sites.","triggerScenarios":"Reading or iterating the reflog of a reference (e.g. `Reference::reflog_iter` internals) where the underlying loose-reflog reader returns `loose::reflog::Error::RefnameValidation` — i.e. the ref name was actually invalid despite the caller assuming validity, typically due to a validation bypass elsewhere or corrupted refs storage.","commonSituations":"Repositories with hand-created or oddly-encoded ref files under `.git/refs/` or `.git/logs/` (case/encoding quirks, Windows-reserved names), or gix versions where validation and iteration disagree about name validity.","solutions":["Verify the reference name is valid: `git check-ref-format --branch <name>` or `repo.find_reference(name)` before touching its reflog","Clean up malformed refs/reflog files under `.git/refs` and `.git/logs` (or recreate them with real git)","Upgrade gix / gix-ref; if a public API lets an invalid name reach the reflog reader, report it upstream"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn ref_name_is_valid(name: &str) -> bool {\n    // mirror git check-ref-format basics\n    !name.is_empty()\n        && !name.starts_with('-')\n        && !name.contains(\"..\")\n        && !name.ends_with(\".lock\")\n        && !name.chars().any(|c| matches!(c, ' ' | '~' | '^' | ':' | '?' | '*' | '[' | '\\\\'))\n        && name.split('/').all(|c| !c.is_empty() && c != \".\" && !c.ends_with(\".lock\"))\n}","typeGuard":"fn as_io_error(err: &gix_ref::store::file::loose::reflog::Error) -> Option<&std::io::Error> {\n    if let gix_ref::store::file::loose::reflog::Error::Io(e) = err { Some(e) } else { None }\n}","tryCatchPattern":"match std::panic::catch_unwind(|| read_reflog(ref)) {\n    Ok(Ok(data)) => data,\n    _ => Vec::new(), // treat unreadable/invalid reflog as absent\n}","preventionTips":["Validate ref names with git check-ref-format rules before creating refs","Avoid hand-creating refs or reflog files with unusual names/encodings","Use gix's own find_reference to confirm a ref exists before reading its reflog","Keep gix-ref current so validation and iteration agree on name validity"],"tags":["rust","panic","reflog","refs","validation"],"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"}