-
Notifications
You must be signed in to change notification settings - Fork 26
Closed
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
I think you can take the same approach as pkgdown does with rmarkdown, i.e. if it fails and it's in quiet mode, you can still print the appropriate part of the stderr that callr has captured.
(It doesn't matter too much here, but in general when you're wrapping errors, you should always use withCallingHandlers not tryCatch)
path <- withCallingHandlers(
callr::r_safe(rmarkdown_render_with_seed, args = args, show = !quiet),
error = function(cnd) wrap_rmarkdown_error(cnd, input_file, call)
)
wrap_rmarkdown_error <- function(cnd, input, call = caller_env()) {
lines <- strsplit(gsub("^\r?\n", "", cnd$stderr), "\r?\n")[[1]]
lines <- lines[nchar(lines) > 0]
# Feeding random text back into cli, so have to escape
lines <- gsub("{", "{{", lines, fixed = TRUE)
lines <- gsub("}", "}}", lines, fixed = TRUE)
cli::cli_abort(
c(
"!" = "Failed to render {.path {input}}.",
set_names(lines, "x")
),
parent = cnd$parent %||% cnd,
trace = cnd$parent$trace,
call = call
)
}cderv
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request