Hmbown/CodeWhale · error · RuntimeError

failed to read git range {commit_range!r}: {exc}

Error message

failed to read git range {commit_range!r}: {exc}

What it means

The checker shells out to 'git log --format=...' over a commit range (default the PR/push range passed as argv) inside the repo root. When git exits non-zero — subprocess.CalledProcessError — it is re-raised as this RuntimeError echoing the exact range, so a bad range fails loudly instead of silently validating nothing.

Source

Thrown at scripts/check-coauthor-trailers.py:176

        if login := github_login_from_noreply(identity.email):
            aliases.setdefault(norm_key(login), identity)
    return aliases


def git_log(commit_range: str) -> list[Commit]:
    try:
        raw = subprocess.check_output(
            [
                "git",
                "log",
                "--format=%H%x00%P%x00%an%x00%ae%x00%s%x00%B%x1e",
                commit_range,
            ],
            cwd=ROOT,
            text=True,
        )
    except subprocess.CalledProcessError as exc:
        raise RuntimeError(f"failed to read git range {commit_range!r}: {exc}") from exc

    commits: list[Commit] = []
    for record in raw.split("\x1e"):
        if not record.strip():
            continue
        # `git log` emits a newline after each record separator. Remove only
        # that framing byte so the next record's full SHA remains exact while
        # preserving commit-body whitespace.
        record = record.lstrip("\n")
        parts = record.split("\x00", 5)
        if len(parts) != 6:
            raise RuntimeError("failed to parse git log output")
        commits.append(Commit(*parts))
    return commits


def is_bot_identity(name: str, email: str) -> bool:
    lowered_name = name.strip().lower()

View on GitHub (pinned to 8880682c63)

Solutions

  1. Run 'git log <same range>' manually in the repo root; git's own stderr will name the bad ref.
  2. Fetch the missing base ref first (git fetch origin <base>) or pass a range that exists locally, e.g. 'origin/main..HEAD'.
  3. In shallow CI clones, fetch with enough depth (fetch --unshallow or --deepen) to cover the range.
  4. Confirm the range syntax: A..B (two-dot excluded range) with valid refs/SHAs on both sides.

Example fix

# before
python3 scripts/check-coauthor-trailers.py HEAD..feature/nonexistent-tip
# after
git fetch origin main
python3 scripts/check-coauthor-trailers.py origin/main..HEAD
Defensive patterns

Strategy: try-catch

Validate before calling

import subprocess

def range_is_readable(commit_range: str) -> bool:
    return subprocess.run(
        ["git", "rev-parse", "--verify", "--quiet", commit_range],
        capture_output=True,
    ).returncode == 0

Try / catch

try:
    commits = git_log(commit_range)
except RuntimeError as error:
    if "failed to read git range" in str(error):
        subprocess.run(["git", "fetch", "--deepen=100"], check=False)
        commits = git_log(commit_range)  # retry once after deepening
    else:
        raise

Prevention

When it happens

Trigger: Passing a malformed or unknown range: 'HEAD..nonexistent-branch', a SHA that does not exist (shallow clone), 'origin/main' when the remote ref is absent, or an empty range string that git rejects. Local dirty state does not matter; only git log's exit code does.

Common situations: Running the script in CI on a shallow clone missing the base ref; typo'd branch names; rebases that rewrote the range so the old tip SHA is unreachable; invoking with no range argument where the script then uses a default that doesn't exist locally.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/68749461809aa807. Report an issue: GitHub.