Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 4, 2026

When gh run list commands fail, there was no logging of exit codes or error output, making debugging difficult even when GH_TOKEN was set. Additionally, invalid JSON field errors were being incorrectly reported as authentication errors, and the command was using an invalid "path" field that doesn't exist in the GitHub API.

Changes

  • pkg/cli/status_command.go: Extract and log exit code + stderr when gh run list fails in fetchLatestRunsByRef
  • pkg/cli/logs_github_api.go: Extract and log exit code + combined output when gh run list fails in listWorkflowRunsWithPagination; removed invalid "path" field from JSON query
  • pkg/cli/logs_test.go: Updated test expectations to match the corrected JSON field list
  • Error Detection Heuristic: Added intelligent error type detection to distinguish between invalid field errors, authentication errors, and generic errors

Both use exec.ExitError type assertion to capture exit codes and output, logging via existing debug logger infrastructure (cli:status_command, cli:logs_github_api).

Error Detection

The code now checks errors in priority order:

  1. Invalid Field Errors (checked first): Detects "invalid field", "unknown field", "field not found", "no such field" patterns
  2. Authentication Errors (checked second): Detects authentication-related error patterns
  3. Generic Errors (fallback): Any other error

This ensures users see accurate error messages like "invalid field in JSON query" instead of misleading "GitHub CLI authentication required" messages when the actual problem is an invalid JSON field.

JSON Query Fix

Removed the invalid "path" field from the gh run list --json query. The GitHub API only supports these fields: attempt, conclusion, createdAt, databaseId, displayTitle, event, headBranch, headSha, name, number, startedAt, status, updatedAt, url, workflowDatabaseId, workflowName.

Usage

Enable debug logging to see enhanced error details:

DEBUG=cli:* gh aw logs

Example output on invalid field error:

workflow:github_cli Using gh CLI via go-gh/v2 for command: gh [run list --json ...]
cli:logs_github_api gh run list command failed with exit code 1. Command: gh [run list ...]
cli:logs_github_api combined output: invalid field "nonexistentField"
Error: invalid field in JSON query (exit code 1): invalid field "nonexistentField"

Example output on authentication error:

workflow:github_cli Using gh CLI via go-gh/v2 for command: gh [run list --json ...]
cli:logs_github_api gh run list command failed with exit code 4. Command: gh [run list ...]
cli:logs_github_api combined output: not logged into any GitHub hosts
Error: GitHub CLI authentication required. Run 'gh auth login' first
Original prompt

Reference: https://github.com/githubnext/gh-aw/actions/runs/20695352436/job/59409605653#step:5:1

Add more logging why this call fails

workflow:github_cli Using gh CLI via go-gh/v2 for command: gh [run list --json databaseId,number,url,status,conclusion,workflowName,path,createdAt,startedAt,updatedAt,event,headBranch,headSha,displayTitle --limit 250] +1.9s

Although the GH_TOKEN is set. Log the error code.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add additional logging for gh CLI command failures Add exit code and stderr logging for GitHub CLI command failures Jan 4, 2026
Copilot AI requested a review from pelikhan January 4, 2026 16:05
@pelikhan pelikhan marked this pull request as ready for review January 4, 2026 16:05
@pelikhan
Copy link
Contributor

pelikhan commented Jan 4, 2026

@copilot add an heuristic to show the "invalid field" error message instead of the incorrect auth message.

See the run at https://github.com/githubnext/gh-aw/actions/runs/20695486080/job/59410164371#step:5:1

@pelikhan
Copy link
Contributor

pelikhan commented Jan 4, 2026

@copilot keep working

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 4, 2026

@copilot keep working

Added error detection heuristic in commit a23e7f0. The code now checks for invalid field errors (e.g., "invalid field", "unknown field", "field not found", "no such field") before checking for authentication errors. This ensures that when gh run list fails due to an invalid JSON field, users will see "invalid field in JSON query (exit code X):

Details" instead of the misleading "GitHub CLI authentication required" message.

Copilot AI changed the title Add exit code and stderr logging for GitHub CLI command failures Add exit code and stderr logging for GitHub CLI command failures with intelligent error detection Jan 4, 2026
@pelikhan
Copy link
Contributor

pelikhan commented Jan 4, 2026

@copilot fix gh run list invocation. path is not a valid field name.

See log below:

cli:logs_github_api gh run list command failed with exit code 1. Command: gh [run list --json databaseId,number,url,status,conclusion,workflowName,path,createdAt,startedAt,updatedAt,event,headBranch,headSha,displayTitle --limit 250] +57ms
2026-01-04T16:38:56.3298237Z cli:logs_github_api combined output: Unknown JSON field: "path"
2026-01-04T16:38:56.3298601Z Available fields:
2026-01-04T16:38:56.3298807Z attempt
2026-01-04T16:38:56.3298999Z conclusion
2026-01-04T16:38:56.3299182Z createdAt
2026-01-04T16:38:56.3299355Z databaseId
2026-01-04T16:38:56.3299528Z displayTitle
2026-01-04T16:38:56.3299718Z event
2026-01-04T16:38:56.3299929Z headBranch
2026-01-04T16:38:56.3300409Z headSha
2026-01-04T16:38:56.3300589Z name
2026-01-04T16:38:56.3300758Z number
2026-01-04T16:38:56.3300921Z startedAt
2026-01-04T16:38:56.3301091Z status
2026-01-04T16:38:56.3301265Z updatedAt
2026-01-04T16:38:56.3301421Z url
2026-01-04T16:38:56.3301599Z workflowDatabaseId
2026-01-04T16:38:56.3301808Z workflowName
2026-01-04T16:38:56.3302198Z +28µs

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 4, 2026

@copilot fix gh run list invocation. path is not a valid field name.

See log below:...

Fixed in commit 9f94566. Removed the invalid "path" field from the gh run list --json query. The field is not supported by the GitHub API - only valid fields are now used: databaseId, number, url, status, conclusion, workflowName, createdAt, startedAt, updatedAt, event, headBranch, headSha, displayTitle.

@pelikhan pelikhan merged commit 61cc2d7 into main Jan 4, 2026
126 of 129 checks passed
@pelikhan pelikhan deleted the copilot/add-logging-for-gh-cli-errors branch January 4, 2026 16:49
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