{"record":{"id":"889faa496718326f","repo":"GitoxideLabs/gitoxide","slug":"could-not-read-reference-err","errorCode":null,"errorMessage":"could not read reference: {err}","messagePattern":"could not read reference: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"gix-tix/src/edit/mod.rs","lineNumber":11,"sourceCode":"use std::{io::Write, process::Command};\n\nuse anyhow::{Context, Result};\n\npub(super) fn loaded_graph(repo: &gix::Repository) -> Result<crate::history::HistoryGraph> {\n    if repo.head_id().is_err() {\n        return Ok(crate::history::HistoryGraph::default());\n    }\n    let mut revisions = Vec::new();\n    for reference in repo.references()?.all()? {\n        let reference = reference.map_err(|err| anyhow::anyhow!(\"could not read reference: {err}\"))?;\n        if reference.name().as_bstr().starts_with(crate::history::STASH_PREFIX)\n            || reference\n                .name()\n                .as_bstr()\n                .starts_with(crate::history::REVIEW_STASH_PREFIX)\n            || undo::is_queue_ref(reference.name().as_bstr())\n        {\n            continue;\n        }\n        let Some(id) = reference.try_id() else { continue };\n        if reference.name().as_bstr() == b\"HEAD\"\n            || repo\n                .find_header(id)\n                .context(\"could not inspect reference target\")?\n                .kind()\n                != gix::object::Kind::Commit\n        {\n            continue;","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-tix/src/edit/mod.rs#L1-L29","documentation":"`loaded_graph` iterates all references to build a history graph; each individual reference read may fail (e.g. the ref points to a missing or non-commit object, or the ref file is corrupt). Such per-reference errors are wrapped as \"could not read reference: {err}\". Note a missing HEAD short-circuits to an empty graph and does not trigger this.","triggerScenarios":"Calling edit_graph_ignores_refs_that_do_not_point_to_commits / loaded_graph when `repo.references()?.all()?` yields an Err for some reference — dangling ref to a pruned object, corrupt packed-refs entry, or reflog/oid decode failure.","commonSituations":"Repos with stale refs after force-pushes and gc; refs pointing to objects deleted by aggressive pruning; corruption from interrupted operations.","solutions":["Identify the broken ref from the inner error and delete or repair it (git update-ref -d)","Run `git fsck` to find dangling/corrupt references","Re-pack refs (git pack-refs --all) to rebuild packed-refs"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-flight: verify all refs resolve to existing objects\nfor r in repo.references()?.all()? {\n    let r = r.map_err(|e| e)?; // surface broken refs before graph building\n    let _ = r.try_id()?;\n}","typeGuard":null,"tryCatchPattern":"match loaded_graph(&repo) {\n    Ok(g) => g,\n    Err(e) if e.to_string().starts_with(\"could not read reference\") => {\n        eprintln!(\"run git fsck and repair broken refs\");\n        HistoryGraph::default()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Run `git fsck` periodically on long-lived repos","Avoid `git gc --prune=now` with stale refs present","Delete dangling refs after force-push cleanup"],"tags":["git","references","corruption"],"backgroundTag":"entity-not-found","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"}