Skip to content

Commit

Permalink
Pkg loading: catch unexpected errors from pkg remotes *
Browse files Browse the repository at this point in the history
In GHA R-CMD-check, it is sometimes observed that remotes::github_remote() or remotes::github_release()
failed, which prevents loading the package even though api.github.com is available:

Error: Error: package or namespace load failed for ‘n2khab’:
 .onAttach failed in attachNamespace() for 'n2khab', details:
  call: github_resolve_ref.github_release(meta$ref %||% ref, meta, host = host,
  error: No releases found for repo inbo/n2khab.
Error: Error: loading failed
Execution halted

This commit will silently ignore this error, as this extra startup message is purely informative.
  • Loading branch information
florisvdh committed Dec 4, 2023
1 parent 2100c83 commit 56e9c06
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions R/n2khab.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,30 @@ utils::globalVariables(c("."))
)
}
if (!is.null(nslookup("api.github.com", error = FALSE))) {
ref <- remotes::github_remote(
"inbo/n2khab",
ref = remotes::github_release()
)$ref
release <- package_version(gsub("\\p{L}*", "", ref, perl = TRUE))
if (packageVersion("n2khab") < release) {
packageStartupMessage(
"\n",
rep("=", getOption("width")),
"\nIt is advised to upgrade n2khab to its current version ",
release,
". Run:\n\n",
'detach("package:n2khab", unload = TRUE)\n',
'install.packages("n2khab", repos = c(inbo = "https://inbo.r-universe.dev",
tryCatch(
{
ref <- remotes::github_remote(
"inbo/n2khab",
ref = remotes::github_release()
)$ref
release <- package_version(gsub("\\p{L}*", "", ref, perl = TRUE))
if (packageVersion("n2khab") < release) {
packageStartupMessage(
"\n",
rep("=", getOption("width")),
"\nIt is advised to upgrade n2khab to its current version ",
release,
". Run:\n\n",
'detach("package:n2khab", unload = TRUE)\n',
'install.packages("n2khab", repos = c(inbo = "https://inbo.r-universe.dev",
CRAN = "https://cloud.r-project.org"))',
"\n",
"library(n2khab)\n",
rep("=", getOption("width"))
)
}
"\n",
"library(n2khab)\n",
rep("=", getOption("width"))
)
}
},
error = function(e) {}
)
}
}

0 comments on commit 56e9c06

Please sign in to comment.