Skip to content

Add error handling in "Get linked issue body" step to distinguish between "no linked issue" and API failures #9

Open

Description

@github-actions

Add error handling in "Get linked issue body" step to distinguish between "no linked issue" and API failures

What

In .github/workflows/_ai-pr-review.yml, the "Get linked issue body" step currently uses || true to swallow all errors from the pipeline:

ISSUE_NUM=$(gh pr view ${{ github.event.pull_request.number }} --json body,title \
  | jq -r '[.title, .body] | join(" ")' \
  | python3 -m cicaid_devtools.lib.linked_issue || true)

This needs to be refactored to distinguish between:

  1. Valid outcome: No linked issue found (the python3 -m cicaid_devtools.lib.linked_issue command exits with a specific code or output indicating no linked issue)
  2. Error: gh pr view or jq fails (e.g., authentication failure, network issue, malformed response)

Why

The current implementation masks real failures. If gh pr view fails due to a token issue or API error, ISSUE_NUM will be empty and the step will proceed as if "No linked issue found" — hiding an authentication or infrastructure problem. This makes debugging difficult and could lead to incorrect workflow behavior (e.g., skipping a review that should have happened, or proceeding without context that should have been available).

How

  1. Separate the commands: Split the pipeline into distinct steps or use explicit error handling:
    • First, fetch the PR data with gh pr view and check its exit code
    • Then, run the python3 -m cicaid_devtools.lib.linked_issue command separately
  2. Check exit codes explicitly: Instead of || true, capture exit codes and handle them:
    • If gh pr view fails, fail the step with a clear error message
    • If python3 -m cicaid_devtools.lib.linked_issue exits with a "no linked issue" code, set ISSUE_NUM to empty and continue
    • If python3 -m cicaid_devtools.lib.linked_issue exits with an unexpected error, fail the step
  3. Add error output: Use GITHUB_OUTPUT or echo "::error::" to provide clear diagnostics when failures occur

Files Affected

  • .github/workflows/_ai-pr-review.yml

Constraints

  • Must not break the existing behavior when no linked issue is found (the workflow should continue normally)
  • Must not introduce new dependencies or require changes to the cicaid_devtools package
  • Must maintain compatibility with the existing continue-on-error pattern used elsewhere in the workflow
  • Out of scope: fixing the misleading condition in the "Fail if provider did not approve" step (separate issue)

LLM tier

Sonnet — This requires moderate design judgment to properly handle exit codes and error paths without breaking existing behavior. It's a single-file change but involves non-trivial logic restructuring.

Success looks like

  • When gh pr view fails (e.g., invalid token), the step fails with a clear error message indicating the API call failed
  • When no linked issue exists, the step succeeds with ISSUE_NUM empty and the workflow continues as before
  • When python3 -m cicaid_devtools.lib.linked_issue encounters an unexpected error, the step fails with diagnostic information
  • The workflow behaves identically to before for all valid scenarios (linked issue found, no linked issue)

Failure looks like

  • The step still swallows errors from gh pr view or jq
  • The workflow fails when no linked issue is found (regression)
  • Error messages are unclear or don't indicate which command failed
  • The change introduces shell syntax errors or breaks the existing pipeline structure

Follow-up from AI review of PR #3.

Implementation notes

FILES: .github/workflows/_ai-pr-review.yml
DONE: Refactor the "Get linked issue body" step to explicitly check exit codes from gh pr view and the python3 -m cicaid_devtools.lib.linked_issue command, failing the step on API/command errors while preserving the current behavior of continuing with an empty ISSUE_NUM when no linked issue exists.

Activity

  1. added
    ai-suggestedSuggested by AI code review
    sonnetSuitable for Claude Sonnet (moderate reasoning)
    on Sep 6, 2026
  2. leonarduk commented on Sep 6, 2026

    @leonarduk
    Owner

    Revision bound exhausted — needs human help.

    Last diff:

    Last test output:
    malformed coder output: no '=== FILE: ... === / === MODE: ... === / === END FILE ===' sections found in coder output

  3. leonarduk commented on Sep 6, 2026

    @leonarduk
    Owner

    FILES: .github/workflows/_ai-pr-review.yml
    DONE: Refactor the "Get linked issue body" step to explicitly check exit codes from gh pr view and the python3 -m cicaid_devtools.lib.linked_issue command, failing the step on API/command errors while preserving the current behavior of continuing with an empty ISSUE_NUM when no linked issue exists.

  4. leonarduk commented on Sep 6, 2026

    @leonarduk
    Owner

    VERDICT: NEEDS_INFO
    MISSING:

    • The issue references a specific exit code from python3 -m cicaid_devtools.lib.linked_issue for "no linked issue" but doesn't specify what that exit code is or how to detect it (e.g., exit code 0 with empty output vs. a specific non-zero code). The implementation needs to know the exact contract of this command.
    • The issue mentions "the existing continue-on-error pattern used elsewhere in the workflow" but doesn't specify which steps use this pattern or how the new error handling should interact with it. Need to see the current workflow structure to understand the context.
    • The issue doesn't specify whether the gh pr view output should be saved to a variable/file for reuse, or if the pipeline should be restructured to avoid re-fetching data. Need clarity on the desired command structure.
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

    Readyai-suggestedSuggested by AI code reviewneeds-infosonnetSuitable for Claude Sonnet (moderate reasoning)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions