{"record":{"id":"ffe558e8e57c8065","repo":"Hmbown/CodeWhale","slug":"gh-repo-view-returned-an-empty-repository-name","errorCode":null,"errorMessage":"`gh repo view` returned an empty repository name","messagePattern":"`gh repo view` returned an empty repository name","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":9317,"sourceCode":"fn run_gh_repo_name() -> Result<String> {\n    let mut cmd = crate::dependencies::Gh::command()\n        .ok_or_else(|| anyhow::anyhow!(\"gh not found on PATH\"))?;\n    cmd.arg(\"repo\")\n        .arg(\"view\")\n        .arg(\"--json\")\n        .arg(\"nameWithOwner\")\n        .arg(\"--jq\")\n        .arg(\".nameWithOwner\");\n    let output = cmd\n        .output()\n        .map_err(|e| anyhow::anyhow!(\"Failed to run `gh repo view`: {e}\"))?;\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();\n        bail!(\"gh repo view failed: {stderr}\");\n    }\n    let name = String::from_utf8_lossy(&output.stdout).trim().to_string();\n    if name.is_empty() {\n        bail!(\"`gh repo view` returned an empty repository name\");\n    }\n    Ok(name)\n}\n\n/// Pick a fence long enough to wrap `replacement` without the replacement's\n/// own backticks closing the block early.\nfn suggestion_fence(replacement: &str) -> String {\n    let mut longest = 0usize;\n    let mut run = 0usize;\n    for ch in replacement.chars() {\n        if ch == '`' {\n            run += 1;\n            longest = longest.max(run);\n        } else {\n            run = 0;\n        }\n    }\n    \"`\".repeat(longest.saturating_add(1).max(3))","sourceCodeStart":9299,"sourceCodeEnd":9335,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/lib.rs#L9299-L9335","documentation":"`gh repo view` was invoked to resolve the current repository's name (e.g. owner/repo for a review publication). The gh CLI exited successfully but wrote nothing to stdout, so the code cannot proceed with an empty repository name and bails.","triggerScenarios":"Running the PR-review flow outside a git repository that has a GitHub remote, or when `gh repo view` resolves no repo despite exit 0 (e.g. detached checkout, gh config oddity, empty output piping).","commonSituations":"Developers running codewhale review commands in a repo without a GitHub origin remote; a broken or shadowed `gh` wrapper script on PATH that prints nothing; CI checkouts without remote info.","solutions":["Run `gh repo view` manually in the same directory to confirm it prints owner/repo; fix the remote (`git remote add origin git@github.com:owner/repo.git`) if it is missing","Pass or set an explicit repository instead of relying on detection, if the command supports it","Upgrade/repair the GitHub CLI (`gh auth status`, reinstall gh) if the binary is a broken wrapper"],"exampleFix":"// before (shell check in repo)\n$ gh repo view   # prints nothing, exit 0\n// after\n$ git remote add origin https://github.com/owner/repo.git\n$ gh repo view   # owner/repo","handlingStrategy":"validation","validationCode":"let out = std::process::Command::new(\"gh\").args([\"repo\",\"view\"]).output()?;\nif out.status.success() && !String::from_utf8_lossy(&out.stdout).trim().is_empty() { /* safe to proceed */ }","typeGuard":"fn resolved_repo_name(stdout: &str) -> Option<&str> { let n = stdout.trim(); (!n.is_empty()).then_some(n) }","tryCatchPattern":null,"preventionTips":["Always init repos with a GitHub origin remote before using review features","Check `gh repo view` works manually after cloning or switching machines","Keep gh CLI up to date and avoid shadowing wrapper scripts on PATH"],"tags":["cli","git","github","empty-output"],"backgroundTag":"empty-result-set","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}