Skip to content

Commit

Permalink
add more calls and update snapshots
Browse files Browse the repository at this point in the history
that should be all of them, there are so many
  • Loading branch information
jayhesselberth committed Nov 29, 2023
1 parent 24ff4cc commit a1c756a
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 38 deletions.
15 changes: 12 additions & 3 deletions R/build-articles.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ build_article <- function(name,
# allow code sharing with building of the index.
vig <- match(name, pkg$vignettes$name)
if (is.na(vig)) {
cli::cli_abort("Can't find article {.file {name}}")
cli::cli_abort(
"Can't find article {.file {name}}",
call = caller_env()
)
}

input <- pkg$vignettes$file_in[vig]
Expand Down Expand Up @@ -368,7 +371,10 @@ data_articles_index <- function(pkg = ".") {
missing <- setdiff(pkg$vignettes$name, c(listed, pkg$package))

if (length(missing) > 0) {
cli::cli_abort("{cli::qty(missing)} Vignette{?s} missing from index: {.file {missing}}")
cli::cli_abort(
"{cli::qty(missing)} Vignette{?s} missing from index: {.file {missing}}",
call = caller_env()
)
}

print_yaml(list(
Expand All @@ -379,7 +385,10 @@ data_articles_index <- function(pkg = ".") {

data_articles_index_section <- function(section, pkg) {
if (!set_contains(names(section), c("title", "contents"))) {
cli::cli_abort("Section must have components {.field title}, {.field contents}")
cli::cli_abort(
"Section must have components {.field title}, {.field contents}",
call = caller_env()
)
}

# Match topics against any aliases
Expand Down
12 changes: 8 additions & 4 deletions R/build-home-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ data_home_sidebar <- function(pkg = ".") {
pkg, c('home', 'sidebar', 'html'), fmt = TRUE, cfg = TRUE
)

cli::cli_abort(c(
"Can't locate {.file {rel_html_path}}.",
x = paste0(msg_fld, " is misconfigured.")
))
cli::cli_abort(
c(
"Can't locate {.file {rel_html_path}}.",
x = paste0(msg_fld, " is misconfigured.")
),
call = caller_env()
)


}
return(read_file(html_path))
Expand Down
13 changes: 8 additions & 5 deletions R/build-news.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,14 @@ data_news <- function(pkg = list()) {
xml2::xml_name()
ulevels <- unique(levels)
if (!identical(ulevels, "h1") && !identical(ulevels, "h2")) {
cli::cli_abort(c(
"Invalid NEWS.md: inconsistent use of section headings.",
i = "Top-level headings must be either all <h1> or all <h2>.",
i = "See {.help pkgdown::build_news} for more details."
))
cli::cli_abort(
c(
"Invalid NEWS.md: inconsistent use of section headings.",
i = "Top-level headings must be either all <h1> or all <h2>.",
i = "See {.help pkgdown::build_news} for more details."
),
call = caller_env()
)
}
if (ulevels == "h1") {
# Bump every heading down a level so to get a single <h1> for the page title
Expand Down
5 changes: 4 additions & 1 deletion R/build-redirects.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ build_redirects <- function(pkg = ".",
cli::cli_rule("Building redirects")
if (is.null(pkg$meta$url)) {
msg_fld <- pkgdown_field(pkg, "url", cfg = TRUE, fmt = TRUE)
cli::cli_abort(paste0(msg_fld, " is required to generate redirects."))
cli::cli_abort(
paste0(msg_fld, " is required to generate redirects."),
call = caller_env()
)
}

purrr::iwalk(
Expand Down
5 changes: 4 additions & 1 deletion R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ init_site <- function(pkg = ".") {
pkg <- as_pkgdown(pkg)

if (is_non_pkgdown_site(pkg$dst_path)) {
cli::cli_abort("{.file {pkg$dst_path}} is non-empty and not built by pkgdown")
cli::cli_abort(
"{.file {pkg$dst_path}} is non-empty and not built by pkgdown",
call = caller_env()
)
}

cli::cli_rule("Initialising site")
Expand Down
1 change: 1 addition & 0 deletions R/markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ markdown_text_inline <- function(text, where = "<inline>", ...) {
if (length(children) > 1) {
cli::cli_abort(
"Can't use a block element in {.var {where}}, need an inline element: {.var {text}}",
call = caller_env()
)
}

Expand Down
11 changes: 7 additions & 4 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,11 @@ check_unique_article_paths <- function(file_in, file_out) {
})
names(same_out_bullets) <- rep_len("x", length(same_out_bullets))

cli::cli_abort(c(
"Rendered articles must have unique names. Rename or relocate:",
same_out_bullets
))
cli::cli_abort(
c(
"Rendered articles must have unique names. Rename or relocate:",
same_out_bullets
),
call = caller_env()
)
}
12 changes: 9 additions & 3 deletions R/rd-example.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ process_conditional_examples <- function(rd) {
grepl("# examplesIf$", x[[1]])
}))
if (length(which_exif) == 0) return(rd)
if (length(which_exif) %% 2 != 0) cli::cli_abort("@examplesIf error, not closed?")
if (length(which_exif) %% 2 != 0) {
cli::cli_abort("@examplesIf error, not closed?", call = caller_env())
}
remove <- integer()
modes <- c("begin", "end")
for (idx in which_exif) {
if (rd[[idx]] != "}) # examplesIf") {
# Start of @examplesIf
if (modes[1] == "end") cli::cli_abort("@examplesIf error, not closed?")
if (modes[1] == "end") {
cli::cli_abort("@examplesIf error, not closed?", call = caller_env())
}
cond_expr <- parse(text = paste0(rd[[idx]], "\n})"))[[1]][[2]]
cond <- eval(cond_expr)
if (isTRUE(cond)) {
Expand All @@ -74,7 +78,9 @@ process_conditional_examples <- function(rd) {
}
} else {
# End of @examplesIf
if (modes[1] == "begin") cli::cli_abort("@examplesIf error, closed twice?")
if (modes[1] == "begin") {
cli::cli_abort("@examplesIf error, closed twice?", call = caller_env())
}
if (isTRUE(cond)) {
remove <- c(remove, idx, idx + 1L)
} else {
Expand Down
5 changes: 4 additions & 1 deletion R/rd-html.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ as_html.tag_Sexpr <- function(x, ...) {
text = as.character(res),
rd = flatten_text(rd_text(as.character(res))),
hide = "",
cli::cli_abort("\\\\Sexpr{{result={results}}} not yet supported")
cli::cli_abort(
"\\\\Sexpr{{result={results}}} not yet supported",
call = caller_env()
)
)
}

Expand Down
5 changes: 4 additions & 1 deletion R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ data_open_graph <- function(pkg = ".") {
check_open_graph <- function(og) {
if (!is.list(og)) {
fog <- friendly_type_of(og)
cli::cli_abort("{.var opengraph} must be a list, not {.val fog}")
cli::cli_abort(
"{.var opengraph} must be a list, not {.val fog}",
call = caller_env()
)
}
supported_fields <- c("image", "twitter")
unsupported_fields <- setdiff(names(og), supported_fields)
Expand Down
2 changes: 1 addition & 1 deletion R/rmarkdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet
output_path <- path_abs(output, pkg$dst_path)

if (!file_exists(input_path)) {
cli::cli_abort("Can't find {src_path(input)")
cli::cli_abort("Can't find {src_path(input)", call = caller_env())
}

cli::cli_inform("Reading {src_path(input)}")
Expand Down
10 changes: 8 additions & 2 deletions R/templates.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ find_template <- function(type, name, ext = ".html", pkg = ".") {

if (length(existing) == 0) {
tname <- paste0(type, "-", name)
cli::cli_abort("Can't find template for {.val {tname}}.")
cli::cli_abort(
"Can't find template for {.val {tname}}.",
call = caller_env()
)
}
existing[[1]]
}
Expand Down Expand Up @@ -44,7 +47,10 @@ templates_dir <- function(pkg = list()) {
if (!is.null(template$path)) {
# Directory specified in yaml doesn't exist, so eagerly error
if (!dir_exists(template$path)) {
cli::cli_abort("Can't find templates path: {src_path(template$path)}")
cli::cli_abort(
"Can't find templates path: {src_path(template$path)}",
call = caller_env()
)
}
path_abs(template$path, start = pkg$src_path)
} else if (!is.null(template$package)) {
Expand Down
9 changes: 6 additions & 3 deletions R/theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ build_bslib <- function(pkg = ".") {

data_deps <- function(pkg, depth) {
if (!file.exists(data_deps_path(pkg))) {
cli::cli_abort("Run {.fn pkgdown::init_site} first.")
cli::cli_abort(
"Run {.fn pkgdown::init_site} first.",
call = caller_env()
)
}

deps_path <- paste0(up_path(depth), "deps")
Expand Down Expand Up @@ -59,7 +62,7 @@ bs_theme_rules <- function(pkg) {
cli::cli_abort(c(
"Unknown theme: {.val {theme}}",
i = "Valid themes are: {.val highlight_styles()}"
))
), call = caller_env())
}
paths <- c(paths, theme_path)

Expand Down Expand Up @@ -110,7 +113,7 @@ check_bootswatch_theme <- function(bootswatch_theme, bs_version, pkg) {
pkgdown_field(pkg, c("template", "bootstrap"))
),
x = "Edit settings in {.file {pkgdown_config_relpath(pkg)}}"
))
), call = caller_env())
}

}
Expand Down
5 changes: 4 additions & 1 deletion R/topics-external.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ get_rd_from_help <- function(package, alias) {
help <- utils::help((alias), (package))
if (length(help) == 0) {
fun <- paste0(package, "::", alias)
cli::cli_abort("Could not find documentation for {.fn {fun}}.")
cli::cli_abort(
"Could not find documentation for {.fn {fun}}.",
call = caller_env()
)
return()
}

Expand Down
15 changes: 12 additions & 3 deletions R/usage.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ usage_type <- function(x) {
out
} else {
untype <- paste0(typeof(x), " (in ", as.character(x), ")")
cli::cli_abort("Unknown type: {.val {untype}}")
cli::cli_abort(
"Unknown type: {.val {untype}}",
call = caller_env()
)
}
}

Expand Down Expand Up @@ -130,7 +133,10 @@ fun_info <- function(fun) {
name = call_name(fun)
)
} else {
cli::cli_abort("Unknown call: {.val {as.character(x[[1]])}}")
cli::cli_abort(
"Unknown call: {.val {as.character(x[[1]])}}",
call = caller_env()
)
}
} else {
list(
Expand Down Expand Up @@ -161,7 +167,10 @@ usage_code.NULL <- function(x) character()
#' @export
usage_code.tag <- function(x) {
if (!identical(class(x), "tag")) {
cli::cli_abort("Undefined tag in usage: {.val class(x)[[1]]}}")
cli::cli_abort(
"Undefined tag in usage: {.val class(x)[[1]]}}",
call = caller_env()
)
}
paste0(purrr::flatten_chr(purrr::map(x, usage_code)), collapse = "")
}
Expand Down
5 changes: 4 additions & 1 deletion R/utils-fs.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ out_of_date <- function(source, target) {
return(TRUE)

if (!file_exists(source)) {
cli::cli_abort("{.fn {source}} does not exist")
cli::cli_abort(
"{.fn {source}} does not exist",
call = caller_env()
)
}

file.info(source)$mtime > file.info(target)$mtime
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/build-reference-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
i In index: 1.
Caused by error in `purrr::map2()`:
i In index: 1.
Caused by error in `.f()`:
Caused by error in `map2_()`:
! Could not find documentation for `rlang::lala()`.

# can use a topic from another package
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/check.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Code
check_pkgdown(pkg)
Condition
Error in `data_articles_index()`:
Error in `check_pkgdown()`:
! Vignettes missing from index: 'articles/nested' and 'width'

# informs if everything is ok
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/rd-html.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
Condition
Error in `purrr::map_chr()`:
i In index: 1.
Caused by error in `.f()`:
Caused by error in `map_()`:
! \\Sexpr{result=verbatim} not yet supported

# bad specs throw errors
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/topics-external.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
Condition
Error in `purrr::map2()`:
i In index: 1.
Caused by error in `.f()`:
Caused by error in `map2_()`:
! Could not find documentation for `base::doesntexist()`.

0 comments on commit a1c756a

Please sign in to comment.