Hmbown/CodeWhale · error · anyhow::Error

gh repo view failed

Error message

gh repo view failed: {stderr}

What it means

The wrapper resolving the current workspace's `owner/name` via `gh repo view --json nameWithOwner` got a non-zero exit; gh's stderr is embedded. This resolution is needed because `gh api` requires an explicit repository path, unlike `gh pr`.

Solutions

  1. Run from inside a repository with a GitHub remote (`git remote -v` to confirm)
  2. Authenticate: `gh auth login`, then test with `gh repo view --json nameWithOwner` yourself
  3. Pass/switch to a workspace whose origin points at the GitHub repo hosting the PR

Example fix

// before (no GitHub remote)
git remote -v  # -> gitlab.com/...
// after
git remote set-url origin git@github.com:owner/name.git
Defensive patterns

Strategy: validation

Validate before calling

gh repo view --json nameWithOwner >/dev/null 2>&1 || { echo 'not in a resolvable GitHub repo'; exit 1; }

Prevention

When it happens

Trigger: Calling the repo-resolution helper from a directory that is not inside a GitHub-backed git repository (no remote gh can resolve), or when gh is unauthenticated/lacks repo access.

Common situations: Running `codewhale pr` outside a cloned repo or in a repo whose `origin` is not on GitHub; expired gh credentials; non-GitHub remotes (GitLab, private servers).

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


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

Appendix: source

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

/// Resolve the `owner/name` repository `gh` believes the current workspace
/// belongs to. `gh api` needs an explicit repository path, unlike `gh pr`
/// which infers it from the working directory.
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 {

View on GitHub (pinned to 73e0f67d83)