Skip to content

Commit

Permalink
use parent = e for simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed May 21, 2024
1 parent d5b2991 commit fa934ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
35 changes: 12 additions & 23 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,33 +188,22 @@ read_meta <- function(path, call = caller_env()) {
if (is.null(path)) {
yaml <- list()
} else {
yaml <- cli_yaml_load(path, call = call) %||% list()
yaml <- withCallingHandlers(
yaml::yaml.load_file(path, error.label = NULL) %||% list(),
error = function(e) {
cli::cli_abort(c(
"x" = "Could not parse the config file.",
"i" = "Edit {.path {path}} to fix the probkem."
),
call = call,
parent = e
)
}
)
}
yaml
}

# Wrapper around yaml::yaml.load_file()
cli_yaml_load <- function(path, call = caller_env()) {
# Tweak the original message to put the location of the error at the end
withCallingHandlers(
yaml::yaml.load_file(
path,
error.label = NULL # suppress path from message.
),
error = function(e) {
yaml_err <- conditionMessage(e)
# Rethrow cli-styled error!
cli::cli_abort(c(
"x" = "Could not parse the config file.",
"!" = yaml_err,
"i" = "Edit {.path {path}} to fix the problem."
),
call = call
)
}
)
}

# Topics ------------------------------------------------------------------

package_topics <- function(path = ".", package = "pkgdown") {
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/_snaps/package.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Condition
Error in `as_pkgdown()`:
x Could not parse the config file.
i Edit 'assets/bad-yaml/_pkgdown.yml' to fix the probkem.
Caused by error in `yaml.load()`:
! Scanner error: mapping values are not allowed in this context at line 2, column 8
i Edit 'assets/bad-yaml/_pkgdown.yml' to fix the problem.

0 comments on commit fa934ac

Please sign in to comment.