{"record":{"id":"f6718b70092ac6c3","repo":"xai-org/grok-build","slug":"path-not-found-in-commit","errorCode":null,"errorMessage":"path '{}' not found in commit: {}","messagePattern":"path '(.+?)' not found in commit: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/session/git.rs","lineNumber":663,"sourceCode":"            tracing::debug!(\n                path = %repo.path().display(),\n                code = ?e.code(),\n                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)","sourceCodeStart":645,"sourceCodeEnd":681,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/session/git.rs#L645-L681","documentation":"read_blob_from_tree looks up a path inside a commit's tree via tree.get_path. When the path does not exist in that commit's tree, git2 returns an error which is wrapped with this message. It means the requested file is absent at the requested revision.","triggerScenarios":"Calling read_version_bytes with GitRef::Treeish(refspec) where `path` was added, renamed, or deleted after (or before) the revision the refspec resolves to.","commonSituations":"Reading a session file version from an older commit that predates the file, typos or case-sensitivity in the path, using a branch name pointing at a commit where the file was moved, or Windows/Unix path separator mismatches.","solutions":["Verify the file exists at that revision: `git ls-tree -r <refspec> -- <path>`","Use a different refspec (e.g. the commit that actually contains the file version)","Check path spelling, case sensitivity, and use repo-relative forward-slash paths","If the file may be missing, handle the error and return empty content or a 'not found' result instead of propagating"],"exampleFix":"// before\nlet bytes = read_version_bytes(repo, \"src/old_name.rs\", \"abc123\")?;\n// after\nlet bytes = match read_version_bytes(repo, \"src/new_name.rs\", \"abc123\") {\n    Ok(b) => b,\n    Err(e) if e.to_string().contains(\"not found in commit\") => Vec::new(), // file absent at revision\n    Err(e) => return Err(e),\n};","handlingStrategy":"fallback","validationCode":"fn path_in_commit(repo: &git2::Repository, refspec: &str, path: &str) -> bool {\n    repo.revparse_single(refspec).ok()\n        .and_then(|o| o.peel_to_commit().ok())\n        .and_then(|c| c.tree().ok())\n        .map(|t| t.get_path(Path::new(path)).is_ok())\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match read_version_bytes(repo, path, version) {\n    Ok(b) => b,\n    Err(e) if e.to_string().contains(\"not found in commit\") => Vec::new(), // treat as absent\n    Err(e) => return Err(e),\n}","preventionTips":["Store repo-relative forward-slash paths, not absolute or OS-specific paths","Record the correct commit SHA alongside file paths in session metadata","Check `git ls-tree -r <ref> -- <path>` when debugging missing historical files"],"tags":["git","file-not-found","revision"],"backgroundTag":"path-not-in-git-tree","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}