{"record":{"id":"b72d72120f9d2aa2","repo":"xai-org/grok-build","slug":"failed-to-read-file-content-for","errorCode":null,"errorMessage":"failed to read file content for '{}': {}","messagePattern":"failed to read file content for '(.+?)': (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/session/git.rs","lineNumber":666,"sourceCode":"                error = %e,\n                \"git.head: unresolvable\",\n            );\n            None\n        }\n    }\n}\n/// The hash stored in HEAD, as `git rev-parse HEAD` prints it. Never loads the\n/// object, so it may name one this repo does not have (see [`head_reference`]).\nfn head_sha(repo: &Repository) -> Option<String> {\n    Some(head_reference(repo)?.target()?.to_string())\n}\nfn read_blob_from_tree(repo: &Repository, tree: &git2::Tree, path: &str) -> Result<Vec<u8>> {\n    let entry = tree\n        .get_path(Path::new(path))\n        .map_err(|e| anyhow::anyhow!(\"path '{}' not found in commit: {}\", path, e))?;\n    let blob = repo\n        .find_blob(entry.id())\n        .map_err(|e| anyhow::anyhow!(\"failed to read file content for '{}': {}\", path, e))?;\n    Ok(blob.content().to_vec())\n}\nfn read_blob_from_index(repo: &Repository, path: &str) -> Result<Vec<u8>> {\n    let index = repo.index()?;\n    let entry = index\n        .get_path(Path::new(path), 0)\n        .ok_or_else(|| anyhow::anyhow!(\"path '{}' not found in staging area\", path))?;\n    let blob = repo.find_blob(entry.id)?;\n    Ok(blob.content().to_vec())\n}\nfn resolve_tree<'a>(repo: &'a Repository, refspec: &str) -> Option<git2::Tree<'a>> {\n    repo.revparse_single(refspec).ok()?.peel_to_tree().ok()\n}\nfn resolve_oid(repo: &Repository, refspec: &str) -> Option<git2::Oid> {\n    repo.revparse_single(refspec)\n        .ok()\n        .and_then(|obj| obj.peel_to_commit().ok())\n        .map(|c| c.id())","sourceCodeStart":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/session/git.rs#L648-L684","documentation":"After finding the tree entry, read_blob_from_tree resolves it to a blob via repo.find_blob. This error wraps a git2 failure at that step, meaning the entry's object id could not be loaded as a blob — typically repository object-store corruption or a missing/packed object.","triggerScenarios":"Calling read_version_bytes on a treeish version where the tree entry references an object id that find_blob cannot resolve (missing object file, failed pack lookup, corrupt object database).","commonSituations":"Interrupted clones or fetches, disk corruption, garbage collection that removed objects while a process held references, or shallow clones missing historical blobs.","solutions":["Run `git fsck --full` to identify and report missing/corrupt objects","Re-fetch or re-clone: `git fetch --unshallow` or fresh `git clone`","Check disk space and permissions in .git/objects","Restore the object from a backup or remote before retrying the read"],"exampleFix":"// before\nlet bytes = read_version_bytes(repo, \"src/main.rs\", version)?; // Err: failed to read file content\n// after\nmatch read_version_bytes(repo, \"src/main.rs\", version) {\n    Ok(b) => b,\n    Err(e) if e.to_string().contains(\"failed to read file content\") => {\n        // object store corrupt; surface actionable guidance\n        return Err(anyhow::anyhow!(\"git object store corrupt; run git fsck: {e}\"));\n    }\n    Err(e) => return Err(e),\n}","handlingStrategy":"retry","validationCode":"fn objects_intact(repo: &git2::Repository) -> bool {\n    // cheap sanity check: resolve HEAD tree\n    repo.revparse_single(\"HEAD\").and_then(|o| o.peel_to_tree()).is_ok()\n}","typeGuard":null,"tryCatchPattern":"match read_version_bytes(repo, path, version) {\n    Ok(b) => b,\n    Err(e) if e.to_string().contains(\"failed to read file content\") => {\n        // suggest `git fsck` / re-clone; retry only after repair\n        anyhow::bail!(\"git object store damaged; run git fsck: {e}\")\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Avoid killing processes mid-clone/fetch; let gc finish","Monitor disk health and free space for .git/objects","Prefer full clones over shallow when historical blob reads are needed"],"tags":["git","object-corruption","blob"],"backgroundTag":"git-object-store-corrupt","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}