Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More information error when quarto_run() fails #184

Open
hadley opened this issue Jun 12, 2024 · 0 comments
Open

More information error when quarto_run() fails #184

hadley opened this issue Jun 12, 2024 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@hadley
Copy link

hadley commented Jun 12, 2024

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 cderv added the enhancement New feature or request label Jun 12, 2024
@cderv cderv added this to the next version milestone Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants