stan-dev / stan-dev/cmdstanr

Add check for invalid GitHub PAT to internal function

Open
#909 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
R
Stars
160
Forks
69
Avg merge
1d 19h
Merged PRs (30d)
15

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace install_cmdstan() into try_download() and download_with_retries(), the entry points named in the issue. Reproduce an invalid PAT and inspect how the 401 Unauthorized warning is suppressed and retries are triggered. Done means the failure is distinguished from other communication problems and reports an informative authentication error without needless retries.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.