{"record":{"id":"73360778646ecde9","repo":"xai-org/grok-build","slug":"failed-to-read","errorCode":null,"errorMessage":"failed to read '{}': {}","messagePattern":"failed to read '(.+?)': (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/session/git.rs","lineNumber":762,"sourceCode":"    } else {\n        let GitRef::Treeish(base_ref) = base else {\n            return None;\n        };\n        let GitRef::Treeish(head_ref) = head else {\n            return None;\n        };\n        diff_compare(repo, base_ref, head_ref, merge_base, opts)\n    }\n}\nfn read_version_bytes(repo: &Repository, path: &str, version: &str) -> Result<Vec<u8>> {\n    match GitRef::parse(version) {\n        GitRef::Workdir => {\n            let full_path = repo\n                .workdir()\n                .ok_or_else(|| anyhow::anyhow!(\"cannot read working files from bare repository\"))?\n                .join(path);\n            std::fs::read(&full_path)\n                .map_err(|e| anyhow::anyhow!(\"failed to read '{}': {}\", path, e))\n        }\n        GitRef::Index => read_blob_from_index(repo, path),\n        GitRef::Treeish(refspec) => {\n            let obj = repo\n                .revparse_single(&refspec)\n                .map_err(|e| anyhow::anyhow!(\"'{}' is not a valid revision: {}\", refspec, e))?;\n            let commit = obj\n                .peel_to_commit()\n                .map_err(|e| anyhow::anyhow!(\"'{}' does not refer to a commit: {}\", refspec, e))?;\n            let tree = commit.tree()?;\n            read_blob_from_tree(repo, &tree, path)\n        }\n    }\n}\n/// Binary files return empty content with is_binary=true.\nfn read_version_content(repo: &Repository, path: &str, version: &str) -> Result<(String, bool)> {\n    let bytes = read_version_bytes(repo, path, version)?;\n    match String::from_utf8(bytes) {","sourceCodeStart":744,"sourceCodeEnd":780,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/session/git.rs#L744-L780","documentation":"For GitRef::Workdir, read_version_bytes performs std::fs::read on the joined workdir path and wraps any I/O failure with this message. It means the working-tree file could not be read — usually it does not exist, though permissions or I/O errors surface here too.","triggerScenarios":"Reading version 'workdir' for a path that was deleted from the working tree, never created, renamed, or is unreadable due to permissions or symlink issues.","commonSituations":"Session references a file the user deleted or moved on disk, cleanup removed the file, file locked by another process, or path casing mismatches on case-sensitive filesystems.","solutions":["Check the file exists (Path::exists / `ls`) before reading","Fall back to the index or HEAD version when the workdir copy is missing","Restore the file (`git checkout -- <path>`) if it was accidentally deleted","Wrap the read and surface the underlying io::Error so ENOENT vs EACCES can be handled distinctly"],"exampleFix":"// before\nlet bytes = read_version_bytes(&repo, \"src/main.rs\", \"workdir\")?; // file deleted\n// after\nlet bytes = match read_version_bytes(&repo, \"src/main.rs\", \"workdir\") {\n    Ok(b) => b,\n    Err(e) if e.to_string().contains(\"failed to read\") => {\n        read_version_bytes(&repo, \"src/main.rs\", \"HEAD\")? // last committed copy\n    }\n    Err(e) => return Err(e),\n};","handlingStrategy":"fallback","validationCode":"fn workdir_file_exists(repo: &git2::Repository, path: &str) -> bool {\n    repo.workdir().map(|w| w.join(path).is_file()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"let bytes = match read_version_bytes(repo, path, \"workdir\") {\n    Ok(b) => b,\n    Err(e) if e.to_string().contains(\"failed to read\") => {\n        read_version_bytes(repo, path, \"HEAD\")? // committed fallback\n    }\n    Err(e) => return Err(e),\n};","preventionTips":["Check Path::is_file before reading workdir paths","Distinguish ENOENT from EACCES by inspecting the wrapped io::Error","Fall back to index/HEAD versions when the working copy is missing"],"tags":["git","io","file-not-found","workdir"],"backgroundTag":"file-read-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}