Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks in error chaining and path display #2403

Merged
merged 5 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion R/build-articles.R
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ data_articles_index <- function(pkg = ".") {

if (length(missing) > 0) {
cli::cli_abort(
"{length(missing)} vignette{?s} missing from index: {.file {missing}}.",
"{length(missing)} vignette{?s} missing from index in \\
{pkgdown_config_href({pkg$src_path})}: {.val {missing}}.",
call = caller_env()
)
}
Expand Down
7 changes: 2 additions & 5 deletions R/build-favicons.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) {
if (has_favicons(pkg) && !overwrite) {
cli::cli_inform(c(
"Favicons already exist in {.path pkgdown}",
"i" = "Set {.var overwrite = TRUE} to re-create."
"i" = "Set {.code overwrite = TRUE} to re-create."
))
return(invisible())
}
Expand Down Expand Up @@ -78,10 +78,7 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) {
result <- content$favicon_generation_result

if (!identical(result$result$status, "success")) {
cli::cli_abort(c(
"API request failed.",
"i" = "{.href [Please submit a bug report](https://github.com/r-lib/pkgdown/issues)}"
))
cli::cli_abort("API request failed.", .internal = TRUE)
}

tmp <- tempfile()
Expand Down
16 changes: 8 additions & 8 deletions R/build-reference-index.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
data_reference_index <- function(pkg = ".") {
data_reference_index <- function(pkg = ".", error_call = caller_env()) {
pkg <- as_pkgdown(pkg)

meta <- pkg$meta[["reference"]] %||% default_reference_index(pkg)
Expand All @@ -13,7 +13,7 @@ data_reference_index <- function(pkg = ".") {

has_icons <- purrr::some(rows, ~ .x$row_has_icons %||% FALSE)

check_missing_topics(rows, pkg)
check_missing_topics(rows, pkg, error_call = error_call)
rows <- Filter(function(x) !x$is_internal, rows)

print_yaml(list(
Expand Down Expand Up @@ -125,19 +125,19 @@ default_reference_index <- function(pkg = ".") {
))
}

check_missing_topics <- function(rows, pkg) {
check_missing_topics <- function(rows, pkg, error_call = caller_env()) {
# Cross-reference complete list of topics vs. topics found in index page
all_topics <- rows %>% purrr::map("names") %>% unlist(use.names = FALSE)
in_index <- pkg$topics$name %in% all_topics

missing <- !in_index & !pkg$topics$internal

if (any(missing)) {
topics <- paste0(pkg$topics$name[missing], collapse = ", ")
abort(c(
cli::cli_abort(c(
"All topics must be included in reference index",
`x` = paste0("Missing topics: ", topics),
i = "Either add to _pkgdown.yml or use @keywords internal"
))
"x" = "Missing topics: {pkg$topics$name[missing]}",
i = "Either add to {pkgdown_config_href({pkg$src_path})} or use @keywords internal"
),
call = error_call)
}
}
6 changes: 3 additions & 3 deletions R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ build_site_external <- function(pkg = ".",
timeout = getOption('pkgdown.timeout', Inf)
)

cli::cli_rule(paste0("Finished building pkgdown site for package ", cli::col_blue(pkg$package)))
cli::cli_rule("Finished building pkgdown site for package {.pkg {pkg$package}}")

preview_site(pkg, preview = preview)
invisible()
Expand All @@ -426,7 +426,7 @@ build_site_local <- function(pkg = ".",

pkg <- section_init(pkg, depth = 0, override = override)

cli::cli_rule(paste0("Building pkgdown site for package ", cli::col_blue(pkg$package)))
cli::cli_rule("Building pkgdown site for package {.pkg {pkg$package}}")
cli::cli_inform("Reading from: {src_path(path_abs(pkg$src_path))}")
cli::cli_inform("Writing to: {dst_path(path_abs(pkg$dst_path))}")

Expand All @@ -453,6 +453,6 @@ build_site_local <- function(pkg = ".",
build_search(pkg, override = override)
}

cli::cli_rule(paste0("Finished building pkgdown site for package ", cli::col_blue(pkg$package)))
cli::cli_rule("Finished building pkgdown site for package {.pkg {pkg$package}}")
preview_site(pkg, preview = preview)
}
5 changes: 3 additions & 2 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ check_pkgdown <- function(pkg = ".") {
data_articles_index(pkg)
data_reference_index(pkg)

cli::cli_alert_success("No problems found in {.file {pkgdown_config_relpath(pkg)}}")
cli::cli_inform(c(
"v" = "No problems found in {pkgdown_config_href({pkg$src_path})}"
))
}

6 changes: 6 additions & 0 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ pkgdown_config_path <- function(path) {
)
)
}
pkgdown_config_href <- function(path) {
cli::style_hyperlink(
text = "_pkgdown.yml",
url = paste0("file://", pkgdown_config_path(path))
)
}

read_meta <- function(path) {
path <- pkgdown_config_path(path)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/build-reference-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
Code
data_reference_index(pkg)
Condition
Error in `check_missing_topics()`:
Error:
! All topics must be included in reference index
x Missing topics: c, e, ?
x Missing topics: c, e, and ?
i Either add to _pkgdown.yml or use @keywords internal

# errors well when a content entry is empty
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/_snaps/check.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Code
check_pkgdown(pkg)
Condition
Error in `check_missing_topics()`:
Error in `check_pkgdown()`:
! All topics must be included in reference index
x Missing topics: ?
i Either add to _pkgdown.yml or use @keywords internal
Expand All @@ -14,10 +14,12 @@
check_pkgdown(pkg)
Condition
Error in `check_pkgdown()`:
! 2 vignettes missing from index: 'articles/nested' and 'width'.
! 2 vignettes missing from index in _pkgdown.yml: "articles/nested" and "width".

# informs if everything is ok

Code
check_pkgdown(pkg)
Message
v No problems found in _pkgdown.yml

Loading