{"record":{"id":"3a4a80085d4ec4d7","repo":"can1357/oh-my-pi","slug":"reference-not-found-name","errorCode":null,"errorMessage":"reference not found: {name}","messagePattern":"reference not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/pi-vcs/src/error.rs","lineNumber":23,"sourceCode":"//! so the TS layer can match on a structured `kind` instead of message text.\n\nuse std::path::PathBuf;\n\n/// Crate-wide result alias.\npub type Result<T, E = Error> = std::result::Result<T, E>;\n\n/// Unified error for all VCS operations.\n#[derive(Debug, thiserror::Error)]\npub enum Error {\n\t/// The directory is not inside a git repository / jj workspace.\n\t#[error(\"not a repository: {path}\")]\n\tNotARepository {\n\t\t/// Directory the lookup started from.\n\t\tpath: PathBuf,\n\t},\n\n\t/// A named ref (branch, tag, `refs/...`) does not exist.\n\t#[error(\"reference not found: {name}\")]\n\tRefNotFound {\n\t\t/// The ref name as given by the caller.\n\t\tname: String,\n\t},\n\n\t/// A revision/object lookup failed (`rev-parse` style spec, blob path,\n\t/// tree).\n\t#[error(\"object not found: {spec}\")]\n\tObjectNotFound {\n\t\t/// The revision or object spec as given by the caller.\n\t\tspec: String,\n\t},\n\n\t/// Cherry-picking `sha` produced an empty commit (already applied or\n\t/// auto-resolved to HEAD). Callers should skip and continue the range —\n\t/// replaces the historical `/the previous cherry-pick is now empty/` stderr\n\t/// regex.\n\t#[error(\"cherry-pick of {sha} is empty\")]","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-vcs/src/error.rs#L5-L41","documentation":"Error::RefNotFound is raised when a named reference (branch, tag, or explicit `refs/...` path) does not exist in the repository. The lookup started fine (the repo is valid) but the requested ref name resolved to nothing.","triggerScenarios":"APIs resolving refs by name: resolving a branch for a diff/log/commit operation (e.g. `resolve_ref(\"origin/main\")` when the branch is not checked out or not fetched), deleting or reading a tag that was never created, or passing a stale ref name from cached state.","commonSituations":"Typos in branch/tag names, branch deleted on the remote (stale `origin/feature`), a repo cloned without the tag set (`--depth 1` skips tags), or local-only branches expected to exist after a fresh clone.","solutions":["Run `git branch -a` / `git tag --list` and confirm the exact ref name; fix the typo.","Fetch the missing ref: `git fetch origin <name>` (or fetch with `--tags`).","Use the default branch (main/master) if you assumed a hardcoded branch name.","In code, list refs via the library first and match case-sensitively before resolving."],"exampleFix":"// before\nlet commit = repo.resolve_ref(\"origin/master\")?; // ref doesn't exist\n// after\nlet name = if repo.ref_exists(\"origin/master\") { \"origin/master\" } else { \"origin/main\" };\nlet commit = repo.resolve_ref(name)?;","handlingStrategy":"validation","validationCode":"fn ref_exists(repo: &pi_vcs::Vcs, name: &str) -> bool {\n    repo.list_refs().map(|refs| refs.iter().any(|r| r.name == name)).unwrap_or(false)\n}\nlet target = [\"origin/main\", \"origin/master\"].into_iter().find(|n| ref_exists(&repo, n))\n    .expect(\"no origin/main or origin/master ref found\");","typeGuard":"fn is_ref_not_found(err: &pi_vcs::Error) -> bool {\n    matches!(err, pi_vcs::Error::RefNotFound { .. })\n}","tryCatchPattern":"match repo.resolve_ref(name) {\n    Err(pi_vcs::Error::RefNotFound { name }) => {\n        eprintln!(\"ref `{name}` not found; available: {:?}\", repo.list_refs()?.iter().map(|r| &r.name).collect::<Vec<_>>());\n    }\n    other => other?,\n}","preventionTips":["List refs via the library and match from that list instead of hardcoding branch/tag names.","Fetch after cloning/checkout in CI so remote-tracking refs exist (`git fetch --prune --tags`).","Never persist ref names across a rebase/prune without revalidating them.","Treat ref names as case-sensitive exact strings — always compare resolved names."],"tags":["vcs","git","ref-not-found","branch","tag"],"backgroundTag":"git-ref-not-found","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}