Skip to content

More informative diagnostics from github_remotes() - #2230

Merged
hadley merged 4 commits into
mainfrom
offline-diagnostics
May 12, 2026
Merged

hadley merged 4 commits into
mainfrom
offline-diagnostics

Conversation

@hadley

@hadley hadley commented Apr 29, 2026

Copy link
Copy Markdown
Member

We more carefully generate an error based on the specific error condition, always including the original error for context.

Fixes #2229. Fixes #1929.

We more carefully generate an error based on the specific error condition, always including the original error for context.

Fixes #2229. Fixes #1929.
@hadley
hadley requested a review from jennybc April 29, 2026 14:04
Comment thread R/utils-github.R
get_gh_repo
)

repo_info <- unwrap_purrr(purrr::pmap(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly unwrapping the purrr error here since get_gh_repo() already includes all the context needed.

Comment thread R/utils-github.R
oops_remotes <- grl$remote[oops]
oops_hosts <- unique(grl$host[oops])
ui_abort(c(
"Unable to get GitHub info for these remotes: {.val {oops_remotes}}.",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new behaviour is to error on the first remote that fails, which is maybe a small downgrade in experience, but I don't think it's significant.

Comment thread R/utils-github.R
}
}

gh_repo_fail_message <- function(cnd, api_url) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These errors (and accompanying snapshots) are probably the most important place to spend your review energy.

Comment thread R/utils-github.R
github_remote_config <- function(github_get = NA, call = caller_env()) {
cfg <- new_github_remote_config()
grl <- github_remotes(github_get = github_get)
grl <- github_remotes(github_get = github_get, call = call)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensures that (e.g.) pr_pull() reports pr_pull() in the error message.

@jennybc jennybc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I made a few inline comments.

My only source of some discomfort is kind of hard-wiring specific interpretations of specific HTTP codes. Of course everything looks/feel right and we are surfacing the more nitty gritty details of the error. I just wouldn't be surprised if we say something a bit off base or confusing now or in the future. But this is absolutely more and better info than usethis currently provides!

Comment thread R/github_token.R Resolved
Comment thread R/utils-github.R Resolved
Comment thread R/utils-github.R Outdated
github_get = TRUE,
call = caller_env()
) {
# Don't even try to get parent info for missing remote

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems to not really describe the if () condition, meaning remote != owner, name.

Also looks like we can early exit here for github_get is FALSE.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment improved. I think it's clearer to handle the three github_get() values in one place below.

Comment thread R/utils-github.R Resolved
Comment thread R/utils-github.R
}

if (identical(github_get, TRUE)) {
# Fail with informative message

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking for myself, maybe a comment about why we need withCallingHandlers() (vs. tryCatch()) is more useful than this? I did have to read up on this FWIW. Or no comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure where we document that but you should always use withCallingHandlers() when wrapping errors.

@hadley
hadley requested a review from jennybc May 12, 2026 20:43
@hadley
hadley merged commit 8501ac1 into main May 12, 2026
15 checks passed
@hadley
hadley deleted the offline-diagnostics branch May 12, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better offline diagnostics Some HTTP 403 errors offer context

2 participants