Skip to content

More information error when quarto_run() failsΒ #184

@hadley

Description

@hadley

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
  )
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions