{"record":{"id":"8d37d8bcd564dd32","repo":"GitoxideLabs/gitoxide","slug":"could-not-read-reference-to-pin-err","errorCode":null,"errorMessage":"could not read reference to pin: {err}","messagePattern":"could not read reference to pin: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-tix/src/ref_tree.rs","lineNumber":829,"sourceCode":"    pin_references_reporting(repository, id, kinds).map(|(pins, _changes)| pins)\n}\n\npub(crate) fn pin_references_reporting(\n    repository: &gix::Repository,\n    id: ObjectId,\n    kinds: &[DecorationKind],\n) -> anyhow::Result<(Vec<crate::history::Pin>, Vec<crate::edit::undo::RefChange>)> {\n    let mut names = Vec::new();\n    for reference in repository\n        .references()\n        .context(\"could not open references while pinning the ref-tree selection\")?\n        .all()\n        .context(\"could not iterate references while pinning the ref-tree selection\")?\n    {\n        let mut reference = match reference {\n            Ok(reference) => reference,\n            Err(err) if crate::history::is_missing_ref(&*err) => continue,\n            Err(err) => return Err(anyhow::anyhow!(\"could not read reference to pin: {err}\")),\n        };\n        let name = reference.name().to_owned();\n        let Some(kind) = pinnable_kind(crate::history::decoration_kind(name.as_bstr())) else {\n            continue;\n        };\n        if !kinds.contains(&kind) {\n            continue;\n        }\n        let Ok(target) = reference.peel_to_id() else {\n            continue;\n        };\n        if target.as_ref() != id {\n            continue;\n        }\n        names.push(name);\n    }\n    names.sort();\n    names.dedup();","sourceCodeStart":811,"sourceCodeEnd":847,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-tix/src/ref_tree.rs#L811-L847","documentation":"While building the set of references to pin in the ref-tree, iteration over `refs.all()` returned a per-reference error that was not the tolerated \"missing ref\" condition. Any other I/O or parse failure reading a reference is converted to this anyhow error wrapping the original `err`.","triggerScenarios":"Calling the ref-tree pinning path (ref_tree.rs:829) when a reference file cannot be read — e.g. a packed-refs entry is malformed, the loose ref file exists but is unreadable, or a filesystem/permission error occurs mid-iteration — and the error does not match `crate::history::is_missing_ref`.","commonSituations":"Concurrent `git gc`/`git pack-refs` rewriting refs while the TUI is open; permission problems on `.git/refs` or `packed-refs`; a corrupted or hand-edited ref file containing a non-OID value.","solutions":["Fix the underlying ref error reported in `{err}` — check permissions and file contents under `.git/refs` and `packed-refs`.","Stop concurrent git processes (gc, pack-refs, fetch) that may be rewriting refs, then retry.","Run `git fsck` to detect and repair corrupted reference files.","If a genuinely unreadable ref should be skipped, extend the match arm to log and `continue` instead of returning, mirroring the `is_missing_ref` arm."],"exampleFix":"// before\nErr(err) => return Err(anyhow::anyhow!(\"could not read reference to pin: {err}\")),\n// after\nErr(err) if crate::history::is_missing_ref(&*err) => continue,\nErr(err) => {\n    eprintln!(\"skipping unreadable reference: {err}\");\n    continue;\n}","handlingStrategy":"try-catch","validationCode":"// Probe ref readability before pinning:\nlet readable = std::fs::read_dir(repo_path.join(\"refs\")).is_ok()\n    && std::fs::read(repo_path.join(\"packed-refs\")).is_ok();","typeGuard":null,"tryCatchPattern":"match pin_selection(&repo, ...) {\n    Err(e) if e.to_string().starts_with(\"could not read reference to pin\") => {\n        eprintln!(\"A ref file is unreadable/corrupt: {e}; run git fsck and check permissions\");\n    }\n    res => res?,\n}","preventionTips":["Avoid running git gc/pack-refs concurrently with the TUI session","Keep `.git/refs` and `packed-refs` readable by the current user","Run `git fsck` periodically to catch corrupted refs early","Tolerate-and-log unreadable refs if the UI should degrade gracefully"],"tags":["git-refs","file-read","filesystem","iteration"],"backgroundTag":"file-read-failed","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"}