Skip to content

unexpected end of JSON input when sending a HEAD request with gh api #9927

@Arthri

Description

@Arthri

Describe the bug

When using gh api to request the headers(-X HEAD) of a non-existent release, the command exits with an exit code of 1 and prints unexpected end of JSON input to stderr. The issue seems to only affect non-existent releases, as requesting a release that exists does not have the same issue.

Steps to reproduce the behavior

  1. Run gh api -X HEAD "repos/cli/cli/releases/tags/nonexistent" ; echo $?
  2. See exit code of 1
  3. Run gh api -X HEAD "repos/cli/cli/releases/tags/v2.62.0" ; echo $?
  4. See exit code of 0

Expected vs actual behavior

Both commands should exit with a code of 0.

Logs

$ gh api -X HEAD "repos/cli/cli/releases/tags/nonexistent" ; echo $?
* Request at 2024-11-16 08:50:11.4016835 +0000 CST m=+0.077060401
* Request to https://api.github.com/repos/cli/cli/releases/tags/nonexistent
> HEAD /repos/cli/cli/releases/tags/nonexistent HTTP/1.1
> Host: api.github.com
> Accept: */*
> Authorization: token ████████████████████
> Content-Type: application/json; charset=utf-8
> Time-Zone: UTC
> User-Agent: GitHub CLI 2.61.0

< HTTP/2.0 404 Not Found
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
< Content-Length: 133
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Sat, 16 Nov 2024 08:50:12 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: github.com
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Vary: Accept-Encoding, Accept, X-Requested-With
< X-Accepted-Oauth-Scopes: repo
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Api-Version-Selected: 2022-11-28
< X-Github-Media-Type: github.v3; format=json
< X-Github-Request-Id: C84C:36F44B:1BC8637:1D38C20:67385CC4
< X-Oauth-Client-Id: ████████████████████
< X-Oauth-Scopes: gist, read:org, repo, workflow
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4998
< X-Ratelimit-Reset: 1731750391
< X-Ratelimit-Resource: core
< X-Ratelimit-Used: 2
< X-Xss-Protection: 0

* Request took 545.7425ms
unexpected end of JSON input
1

$ gh api -X HEAD "repos/cli/cli/releases/tags/v2.62.0" ; echo $?
* Request at 2024-11-16 08:50:15.5118526 +0000 CST m=+0.067254201
* Request to https://api.github.com/repos/cli/cli/releases/tags/v2.62.0
> HEAD /repos/cli/cli/releases/tags/v2.62.0 HTTP/1.1
> Host: api.github.com
> Accept: */*
> Authorization: token ████████████████████
> Content-Type: application/json; charset=utf-8
> Time-Zone: UTC
> User-Agent: GitHub CLI 2.61.0

< HTTP/2.0 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
< Cache-Control: private, max-age=60, s-maxage=60
< Content-Length: 37358
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Sat, 16 Nov 2024 08:50:16 GMT
< Etag: "3ee4cd9b98ceb34bcc6d030cac0282e4367b29115cfa1e9a055661b2c29c1a7c"
< Last-Modified: Thu, 14 Nov 2024 16:12:31 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: github.com
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Vary: Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding, Accept, X-Requested-With
< X-Accepted-Oauth-Scopes: repo
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Api-Version-Selected: 2022-11-28
< X-Github-Media-Type: github.v3; format=json
< X-Github-Request-Id: C84D:35C4BD:1B9215D:1D027A6:67385CC8
< X-Oauth-Client-Id: ████████████████████
< X-Oauth-Scopes: gist, read:org, repo, workflow
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4997
< X-Ratelimit-Reset: 1731750391
< X-Ratelimit-Resource: core
< X-Ratelimit-Used: 3
< X-Xss-Protection: 0

* Request took 536.3801ms
0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggh-apirelating to the gh api commandp3Affects a small number of users or is largely cosmetic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions