Skip to content

Commit

Permalink
Tweaks in error chaining and path display (r-lib#2403)
Browse files Browse the repository at this point in the history
* cli fixes
* Fix chaining in `check_pkgdown()` + add hyperlink to `_pkgdown.yml` in error message.
* Actually show snapshot by using `cli_inform()` instead of `cli_alert_success()`.
* Remove unrelated changes
  • Loading branch information
olivroy authored and SebKrantz committed Jun 1, 2024
1 parent 44b92b0 commit 1b6d2b2
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 23 deletions.
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)

# This removes shorthands from reference index
Expand All @@ -20,7 +20,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 @@ -132,19 +132,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 @@ -425,7 +425,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 Down Expand Up @@ -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

0 comments on commit 1b6d2b2

Please sign in to comment.