Skip to content

Add check for invalid GitHub PAT to internal function #909

@wpetry

Description

@wpetry

Is your feature request related to a problem? Please describe.
This feature would add more graceful and informative error handling for cases when the user's GitHub PAT in .Renviron is invalid due to expiration, inadequate permissions, or typos/copy errors.

When an invalid PAT is provided in the user's .Renviron, it is not possible to install_cmdstan(). The function fails to retrieve the version list from GitHub, and will retry several times before stopping with an error. On the user side, it appears that GitHub is not responding, but the URL provided in the message loads fine on a browser. Like many other .Renviron problems, it's difficult to diagnose that is the cause of the failure. But seems worth addressing here because cmdstanr uses a PAT stored in .Renviron to retrieve GitHub credentials.

Describe the solution you'd like
Add a check to ensure that the user's PAT does not cause a '401 Unauthorized' HTTP status when supplied to GitHub. It's not clear to me the best way to do this. Currently, try_download() throws an error when an invalid PAT is supplied, but it suppresses the warning that contains the '401 Unauthorized' HTTP status code. Some ideas:

  1. Add a new internal function that checks for different causes of failure to communicate with the GitHub API. This would also help diagnose whether the failure is due to other common causes (e.g., no internet connectivity).
  2. Modify try_download() to capture warnings when an invalid PAT is supplied. download_with_retries() could then parse these warnings to avoid needless retries with a bad PAT.
  3. Retry without supplying a PAT.

Describe alternatives you've considered
None

Additional context
None

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions