r-lib / remotes

Install R packages from GitHub, GitLab, Bitbucket, git, svn repositories, URLs
https://remotes.r-lib.org/
Other
332 stars 152 forks source link

Vague error message for install_gitlab - OpenSSL issue #762

Closed reisner closed 11 months ago

reisner commented 1 year ago

Hi there,

I've recently encountered an error when trying to run install_gitlab from a local gitlab repository. I encountered this error:

> remotes::install_gitlab(c('project/path'),host = 'host.url.here',auth_token ='my-gitlab-token', upgrade = 'never')
Error: Failed to install 'unknown package' from GitLab:
  cannot open URL 'https://host.url.here/api/v4/projects/project%2Fpath/repository/files/DESCRIPTION/raw?ref=HEAD'

When I click on the URL, it works fine, and the error message didnt give much more info. After a bunch of digging, I discovered that it was an SSL problem. I was able to figure out the details for this by trying to pull the package with curl:

# curl --header "PRIVATE-TOKEN: my-gitlab-token" "https://host.url.here/api/v4/projects/project%2Fpath/repository/files/DESCRIPTION/raw?ref=HEAD" --output tmp.txt
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (35) error:0A000152:SSL routines::unsafe legacy renegotiation disabled

The error unsafe legacy renegotiation disabled is the source of this problem, and has led me to this stack overflow answer, which made me realize this is likely a firewall issue.

Anyways, the issue is that the original error of "cannot open URL" was very vague and I had to figure out what the source of the error was. I think this error message could at least display the source error (i.e. the output from curl). This could potentially also help resolve some of the other issues on this package like this one, and this one.

gaborcsardi commented 1 year ago

Unfortunately it seems that that's the error message remotes gets from utils::download.file(), and there isn't much it can do.

reisner commented 1 year ago

OK thanks for the info. I've tracked it down to this line in base_download_headers in R/download.R:

  suppressWarnings(
    utils::download.file(
      url,
      path,
      method = method,
      quiet = quiet,
      mode = "wb",
      headers = headers
    )
  )

When I run it like that, I get this output:

Error in utils::download.file(url, path, method = method, quiet = quiet,  : 
  cannot open URL 'https://host.url.here/api/v4/projects/project%2Fpath/repository/files/DESCRIPTION/raw?ref=HEAD'

However, when I dont use suppressWarnings, I see this:

Error in utils::download.file(url, path, method = method, quiet = quiet,  : 
  cannot open URL 'https://host.url.here/api/v4/projects/project%2Fpath/repository/files/DESCRIPTION/raw?ref=HEAD'
In addition: Warning message:
In utils::download.file(url, path, method = method, quiet = quiet,  :
  URL 'https://host.url.here/api/v4/projects/project%2Fpath/repository/files/DESCRIPTION/raw?ref=HEAD': status was 'SSL connect error'

Note the warning about the SSL connect error. Looks like utils::download.file can see that it's an SSL issue, but it's just exposing this as a warning, not an error. :(

Is there any way to raise this issue in the utils base library?

reisner commented 1 year ago

I guess the alternative is to remove the suppressMessages here? That would allow for more information to bubble up.