r-lib / gh

Minimalistic GitHub API client in R
https://gh.r-lib.org
Other
223 stars 52 forks source link

Error when response header has no 'link' #189

Closed mpadge closed 7 months ago

mpadge commented 9 months ago

Hi @gaborcsardi. I' seeing a lot of issues like this, which i suspect might be due to curl upgrades:

system("curl --version", intern = TRUE)
#> [1] "curl 8.5.0 (x86_64-pc-linux-gnu) libcurl/8.5.0 OpenSSL/3.2.0 zlib/1.3 brotli/1.1.0 zstd/1.5.5 libidn2/2.3.4 libpsl/0.21.2 (+libidn2/2.3.4) libssh2/1.11.0 nghttp2/1.58.0"
#> [2] "Release-Date: 2023-12-06"                                                                                                                                                
#> [3] "Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp"                                        
#> [4] "Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM PSL SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd"

This is taken from the main gh function:

req <- list (
    method = "GET",
    url = "https://api.github.com/repos/r-lib/actions/releases",
    headers = c (
        'User-Agent' = "https://github.com/r-lib/gh",
        'Accept' = "application/vnd.github.v3+json",
        'Authorization' = "token ghp_<token>"
    ),
    query = NULL,
    body = NULL,
    dest = NULL,
    max_wait = 600,
    max_rate = NULL
)

raw <- gh:::gh_make_request(req)
gh_response <- gh:::gh_process_response(raw, req)

headers <- attr(gh_response, "response")
str(headers)
#> List of 27
#>  $ server                                : chr "GitHub.com"
#>  $ date                                  : chr "Mon, 22 Jan 2024 20:13:06 GMT"
#>  $ content-type                          : chr "application/json; charset=utf-8"
#>  $ cache-control                         : chr "private, max-age=60, s-maxage=60"
#>  $ vary                                  : chr "Accept, Authorization, Cookie, X-GitHub-OTP"
#>  $ etag                                  : chr "W/\"ab43ce4572d15992d80dba394e836cefe7da4cec45130206b7fa5148e875ca2e\""
#>  $ x-oauth-scopes                        : chr "notifications, read:org, repo, user, workflow"
#>  $ x-accepted-oauth-scopes               : chr "repo"
#>  $ github-authentication-token-expiration: chr "2024-04-15 09:38:41 UTC"
#>  $ x-github-media-type                   : chr "github.v3; format=json"
#>  $ x-github-api-version-selected         : chr "2022-11-28"
#>  $ x-ratelimit-limit                     : chr "5000"
#>  $ x-ratelimit-remaining                 : chr "4978"
#>  $ x-ratelimit-reset                     : chr "1705954559"
#>  $ x-ratelimit-used                      : chr "22"
#>  $ x-ratelimit-resource                  : chr "core"
#>  $ access-control-expose-headers         : chr "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-"| __truncated__
#>  $ access-control-allow-origin           : chr "*"
#>  $ strict-transport-security             : chr "max-age=31536000; includeSubdomains; preload"
#>  $ x-frame-options                       : chr "deny"
#>  $ x-content-type-options                : chr "nosniff"
#>  $ x-xss-protection                      : chr "0"
#>  $ referrer-policy                       : chr "origin-when-cross-origin, strict-origin-when-cross-origin"
#>  $ content-security-policy               : chr "default-src 'none'"
#>  $ vary                                  : chr "Accept-Encoding, Accept, X-Requested-With"
#>  $ content-encoding                      : chr "gzip"
#>  $ x-github-request-id                   : chr "80F2:2B0679:7D4704:7E95D8:65AECC51"
#>  - attr(*, "class")= chr "httr2_headers"
headers$link
#> NULL

Created on 2024-01-22 with reprex v2.1.0

So the request works, and returns headers (and the expected body, not shown here but confirmed), but then these lines use absence of "header$link$ to diagnose (i presume) an absence of any returned response: https://github.com/r-lib/gh/blob/ee2dbed977d71f2a3bae6d118d6a1a597d9575d2/R/pagination.R#L3-L7

And that NA value is then passed back out on these lines directly to {httr2}, causing the error i'm seeing here: https://github.com/r-lib/gh/blob/ee2dbed977d71f2a3bae6d118d6a1a597d9575d2/R/pagination.R#L54-L55

Could you maybe check with updated version of curl?

mpadge commented 9 months ago

Update: I can replicate this in fresh tidyverse container with libcurl4 7.81.0 as well.

mpadge commented 7 months ago

I'll close this for now, and revisit later if needed.