Hmbown/CodeWhale · error · anyhow::Error

`gh repo view` returned an empty repository name

Error message

`gh repo view` returned an empty repository name

What it means

`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.

Solutions

  1. 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
  2. Pass or set an explicit repository instead of relying on detection, if the command supports it
  3. Upgrade/repair the GitHub CLI (`gh auth status`, reinstall gh) if the binary is a broken wrapper

Example fix

// before (shell check in repo)
$ gh repo view   # prints nothing, exit 0
// after
$ git remote add origin https://github.com/owner/repo.git
$ gh repo view   # owner/repo
Defensive patterns

Strategy: validation

Validate before calling

let out = std::process::Command::new("gh").args(["repo","view"]).output()?;
if out.status.success() && !String::from_utf8_lossy(&out.stdout).trim().is_empty() { /* safe to proceed */ }

Type guard

fn resolved_repo_name(stdout: &str) -> Option<&str> { let n = stdout.trim(); (!n.is_empty()).then_some(n) }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/ffe558e8e57c8065. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/lib.rs:9317

fn run_gh_repo_name() -> Result<String> {
    let mut cmd = crate::dependencies::Gh::command()
        .ok_or_else(|| anyhow::anyhow!("gh not found on PATH"))?;
    cmd.arg("repo")
        .arg("view")
        .arg("--json")
        .arg("nameWithOwner")
        .arg("--jq")
        .arg(".nameWithOwner");
    let output = cmd
        .output()
        .map_err(|e| anyhow::anyhow!("Failed to run `gh repo view`: {e}"))?;
    if !output.status.success() {
        let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
        bail!("gh repo view failed: {stderr}");
    }
    let name = String::from_utf8_lossy(&output.stdout).trim().to_string();
    if name.is_empty() {
        bail!("`gh repo view` returned an empty repository name");
    }
    Ok(name)
}

/// Pick a fence long enough to wrap `replacement` without the replacement's
/// own backticks closing the block early.
fn suggestion_fence(replacement: &str) -> String {
    let mut longest = 0usize;
    let mut run = 0usize;
    for ch in replacement.chars() {
        if ch == '`' {
            run += 1;
            longest = longest.max(run);
        } else {
            run = 0;
        }
    }
    "`".repeat(longest.saturating_add(1).max(3))

View on GitHub (pinned to 73e0f67d83)