Skip to content

fix(gh): tolerate non-JSON warnings before gh pr view output - #27

Merged
kitlangton merged 1 commit into
mainfrom
fix/tolerate-gh-warnings
Jun 30, 2026
Merged

fix(gh): tolerate non-JSON warnings before gh pr view output#27
kitlangton merged 1 commit into
mainfrom
fix/tolerate-gh-warnings

Conversation

@kitlangton

Copy link
Copy Markdown
Owner

Summary

Fixes #12gh pr view --json ... can emit warning lines (e.g. auth expiry notices) to stdout before the JSON payload, causing JSON.parse to fail with "returned invalid JSON" even though the JSON itself is valid when run directly in a shell.

Fix

Add extractJson() which finds the first { or [ and its matching closer (} or ]) in the output, stripping any leading/trailing non-JSON text before parsing. Applied to all three GitHub decoders (decodePullList, decodePullView, decodePullWatch).

Test

Added a test simulating gh emitting an auth-warning line before the JSON payload, confirming the decoder successfully extracts and parses the JSON.

Verification

  • bun run typecheck
  • bun run test (127 passing)
  • bun run format:check
  • bun run lint

gh can emit warning lines (e.g. auth expiry notices) to stdout before
the JSON payload, causing JSON.parse to fail with 'returned invalid JSON'
even though the JSON itself is valid. The decoder now extracts the JSON
payload by finding the first { or [ and matching closer, so leading or
trailing non-JSON output is stripped before parsing.

Fixes #12.
@kitlangton
kitlangton merged commit 7aa7d11 into main Jun 30, 2026
1 check passed
@kitlangton
kitlangton deleted the fix/tolerate-gh-warnings branch June 30, 2026 18:07
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.

stack sync fails with returned invalid JSON even though gh pr view succeeds

1 participant