Skip to content

merged_pr_by_head silently swallows all exceptions, masking authentication and network failures #79

Description

@bjester

Observed Behavior

In GithubCLI.merged_pr_by_head(), any exception that occurs during gh pr list execution—including missing GitHub authentication (gh auth login), rate limits, network timeouts, or invalid repository arguments—is caught by a bare except Exception: pass. The method silently returns an empty list []. Consequently, commands like treefort prune report "No merged PR worktrees found to prune." without informing the user that GitHub communication failed.

Expected Behavior

GithubCLI.merged_pr_by_head() should log errors, warnings, or propagate appropriate diagnostic information so that authentication or network failures are transparent to the user and not disguised as "no merged PRs found".

Steps to Reproduce

  1. Log out of GitHub CLI (gh auth logout) or disconnect network connectivity.
  2. In a project with existing worktrees, execute treefort prune.
  3. gh pr list exits with an error status (e.g. To get started with GitHub CLI, please run: gh auth login).
  4. merged_pr_by_head catches CalledProcessError via except Exception: pass and returns [].
  5. Prune command reports: "No merged PR worktrees found to prune." with zero warnings about authentication failure.

Minimal Reproduction Environment / Conditions

  • Version / Branch / Commit: release-v0.5.x@6d07c0c
  • Component: treefort.gh.GithubCLI.merged_pr_by_head

Errors, Logs & Telemetry

# src/treefort/gh.py:57-65
try:
    with self.run(args) as p:
        output = p.stdout
    prs = json.loads(output)
    if prs:
        return prs
except Exception:
    pass  # Silently swallows CalledProcessError, json.JSONDecodeError, etc.
return []

Deliverables & Testing Requirements

  • Log caught exceptions at warning or error level with command output details.
  • Guard against None values when config.owner or config.name is missing to prevent passing --repo None/None.
  • Regression Safety: Add a unit test in tests/test_gh.py verifying that when self.run() raises an exception, the error is logged and handled appropriately.

Technical Pointers & Root Cause Clues

  • Suspected Components: src/treefort/gh.py:43-65 (merged_pr_by_head)
  • Related Commits: 21941c3, bd7ed4c

Notes & Edge Cases

  • When users run treefort prune in CI or environments without GH tokens, they should immediately be alerted why PR queries are returning empty.

Metadata

Severity / Priority: P2 (Normal)
Area: bug, gh, prune

AI Usage

Drafted with Gemini following the DEEP framework based on code review findings against release-v0.5.x. Reproduction conditions and code references were verified in the codebase.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2 - NormalShould fix but can waitbugSomething isn't working

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions