Skip to content

fix: add Copilot CLI auth error handling to pipeline - #8

Merged
robpitcher merged 5 commits into
modernizefrom
fix/copilot-auth-error-handling
Apr 15, 2026
Merged

fix: add Copilot CLI auth error handling to pipeline#8
robpitcher merged 5 commits into
modernizefrom
fix/copilot-auth-error-handling

Conversation

@robpitcher

Copy link
Copy Markdown
Owner

Problem

The modernize pipeline fails with exit code 1 and zero output when the Copilot CLI cannot authenticate. The default GITHUB_TOKEN does not include Copilot API scope, making this the expected failure on first run.

Fix

  • Capture copilot exit code instead of letting bash -e silently exit
  • Display actionable error message pointing to PAT creation
  • Update auth comments to clarify COPILOT_TOKEN is required (not optional)
  • Applied consistently across all 3 pipeline stages

Required Action

After merging this PR, create a Fine-Grained PAT with Copilot Requests: Read permission and add it as a COPILOT_TOKEN repo secret.

The Copilot CLI exits with code 1 and zero output when the token
lacks Copilot API scope. This makes failures cryptic in Actions logs.

Changes:
- Capture copilot exit code and display actionable error message
- Direct users to create a Fine-Grained PAT with Copilot Requests scope
- Update auth comments to clarify COPILOT_TOKEN is required (not optional)
- Apply to all three stages for consistent error handling

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 14, 2026 19:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves the Modernize Pipeline GitHub Actions workflow to fail with actionable output when the Copilot CLI cannot authenticate (instead of exiting with code 1 and no helpful logs).

Changes:

  • Adds explicit Copilot CLI startup logging, captures exit codes, and prints actionable ::error:: guidance on failure.
  • Updates inline auth guidance to clarify that a Fine-Grained PAT in COPILOT_TOKEN is needed for Copilot API scope.
  • Applies the same error-handling pattern to stages 1–3 (with some inconsistencies noted in comments).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/modernize-pipeline.yml Outdated
Comment thread .github/workflows/modernize-pipeline.yml Outdated
Comment on lines +211 to +215
echo "::error::Copilot CLI failed with exit code $COPILOT_EXIT."
echo "::error::This is most likely an authentication issue — the default GITHUB_TOKEN does not include Copilot API scope."
echo "::error::FIX: Create a Fine-Grained PAT with 'Copilot Requests: Read' permission"
echo "::error:: and add it as a COPILOT_TOKEN repo secret (Settings → Secrets and variables → Actions)."
exit 1

Copilot AI Apr 14, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new error-handling block is not applied consistently across stages: Stage 1 includes a direct PAT-creation URL, but Stage 2 does not. This undermines the “actionable error message” goal and diverges from the PR description (“applied consistently across all 3 pipeline stages”). Consider adding the same "See: https://github.com/settings/personal-access-tokens/new" line here (and keep the wording in sync across stages).

Copilot uses AI. Check for mistakes.
echo ""
echo "::error::Copilot CLI failed with exit code $COPILOT_EXIT."
echo "::error::This is most likely an authentication issue — the default GITHUB_TOKEN does not include Copilot API scope."
echo "::error::FIX: Create a Fine-Grained PAT with 'Copilot Requests: Read' permission"

Copilot AI Apr 14, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as Stage 2: Stage 1’s handler includes a direct PAT-creation URL but Stage 3’s does not, so the guidance is inconsistent across stages. To keep the pipeline UX consistent, add the missing link (or otherwise unify the message text across all stages).

Suggested change
echo "::error::FIX: Create a Fine-Grained PAT with 'Copilot Requests: Read' permission"
echo "::error::FIX: Create a Fine-Grained PAT with 'Copilot Requests: Read' permission at https://github.com/settings/personal-access-tokens/new"

Copilot uses AI. Check for mistakes.
Comment thread .github/workflows/modernize-pipeline.yml Outdated
Comment thread .github/workflows/modernize-pipeline.yml Outdated
McManus (Backend Dev) and others added 4 commits April 15, 2026 01:47
All 6 review comments addressed:
- Removed GITHUB_TOKEN fallback from all 3 stages (comments 1-3)
- Added preflight check for empty COPILOT_TOKEN in all 3 stages
- Added PAT URL to Stage 2 error messages (comment 4)
- Added PAT URL to Stage 3 error messages (comment 5)
- Quoted $COPILOT_EXIT in all 3 stages (comment 6)

All stages now have identical structure for token validation:
1. env block with COPILOT_GITHUB_TOKEN (no fallback)
2. Preflight check for empty token
3. Copilot CLI invocation with set +e/set -e
4. Post-CLI error handler with quoted $COPILOT_EXIT and complete error messages

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The repo secret name now matches the env var the Copilot CLI reads,
eliminating the confusing COPILOT_TOKEN → COPILOT_GITHUB_TOKEN mapping.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove GITHUB_TOKEN fallback, add preflight token validation to all stages
- Add PAT URL reference to all error messages for actionable feedback
- Quote COPILOT_EXIT variable for robustness
- Rename COPILOT_TOKEN env var references to COPILOT_GITHUB_TOKEN for semantic clarity
- All three pipeline stages now have consistent auth error handling

Addressed all 6 PR #8 review comments.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@robpitcher
robpitcher merged commit 4b6e9f7 into modernize Apr 15, 2026
5 checks passed
@robpitcher
robpitcher deleted the fix/copilot-auth-error-handling branch April 15, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants