{"record":{"id":"b7e7549a36d6d560","repo":"xai-org/grok-build","slug":"is-not-a-valid-revision","errorCode":null,"errorMessage":"'{}' is not a valid revision: {}","messagePattern":"'(.+?)' is not a valid revision: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/session/git.rs","lineNumber":768,"sourceCode":"        };\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) {\n        Ok(text) => Ok((text, false)),\n        Err(_) => Ok((String::new(), true)),\n    }\n}\nfn read_version_text(repo: &Repository, path: &str, version: &str) -> Option<String> {\n    read_version_content(repo, path, version)","sourceCodeStart":750,"sourceCodeEnd":786,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/session/git.rs#L750-L786","documentation":"For GitRef::Treeish, read_version_bytes resolves the refspec with git2's revparse_single. If the string is not a valid revision (unknown branch/tag/SHA or malformed syntax), this error is thrown. It validates the user- or session-supplied version identifier before any content is read.","triggerScenarios":"Calling read_version_content with a treeish version string that does not resolve: deleted branch, typo'd SHA, nonexistent tag, or invalid syntax like an empty or dangling refspec.","commonSituations":"Session history referencing a branch that was later deleted, truncated SHAs that no longer resolve after garbage collection, tags removed on the remote, or versions stored with wrong format.","solutions":["Validate the ref with `git rev-parse --verify <refspec>` before reading","Use a full commit SHA instead of a branch name so history stays stable after branch deletion","Check `git branch -a` / `git tag -l` for the correct name; fetch if the object is missing (`git fetch --all`)","Handle the error by listing available versions instead of propagating a raw failure"],"exampleFix":"// before\nlet bytes = read_version_bytes(&repo, \"src/main.rs\", \"feature-x\")?; // branch deleted\n// after\nlet bytes = match read_version_bytes(&repo, \"src/main.rs\", \"feature-x\") {\n    Ok(b) => b,\n    Err(e) if e.to_string().contains(\"is not a valid revision\") => {\n        read_version_bytes(&repo, \"src/main.rs\", \"HEAD\")? // stable fallback\n    }\n    Err(e) => return Err(e),\n};","handlingStrategy":"validation","validationCode":"fn revision_exists(repo: &git2::Repository, refspec: &str) -> bool {\n    repo.revparse_single(refspec).is_ok()\n}\nif !revision_exists(&repo, version) {\n    anyhow::bail!(\"unknown revision: {}\", version);\n}","typeGuard":null,"tryCatchPattern":"match read_version_bytes(repo, path, version) {\n    Ok(b) => b,\n    Err(e) if e.to_string().contains(\"is not a valid revision\") => {\n        read_version_bytes(repo, path, \"HEAD\")? // stable fallback\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Persist full commit SHAs, not branch names, in version metadata","Validate refspecs with `git rev-parse --verify` before storing them","Fetch missing objects (`git fetch --all`) when external SHAs are referenced"],"tags":["git","revision","invalid-ref"],"backgroundTag":"invalid-git-revision","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}