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

Informative error messages #16

Closed
wlandau opened this issue Jul 1, 2022 · 4 comments
Closed

Informative error messages #16

wlandau opened this issue Jul 1, 2022 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@wlandau
Copy link

wlandau commented Jul 1, 2022

When quarto_render() errors out due to an error in a code chunk, it would be helpful if the condition message were more informative. Tools like targets would have an easier time logging and documenting errors. From ropensci/tarchetypes#99.

lines <- c(
  "---",
  "title: 'error'",
  "format: html",
  "editor: source",
  "---",
  "",
  "```{r}",
  "stop('true message')",
  "```"
)
writeLines(lines, "report.qmd")
tryCatch(
  quarto::quarto_render("report.qmd", quiet = TRUE),
  error = function(condition) {
    print(sprintf("Quarto error message: %s", conditionMessage(condition)))
  }
)
#> [1] "Quarto error message: ! System command 'quarto' failed"

Created on 2022-07-01 by the reprex package (v2.0.1)

@cderv cderv added the enhancement New feature or request label Jul 4, 2022
@cderv cderv added this to the next version milestone Jan 23, 2024
@cderv
Copy link
Collaborator

cderv commented Jan 23, 2024

@cderv
Copy link
Collaborator

cderv commented Jan 23, 2024

This is what we get currently with dev version and quiet = FALSE

> quarto_render("report.qmd", quiet = FALSE)
Error in `quarto_render()`:
! Error running quarto cli:processing file: report.qmd
  |...................................                 |  67% [unnamed-chunk-1]


Quitting from lines 8-9 [unnamed-chunk-1] (report.qmd)
Error:
! true message
                                                                                                            
Exécution arrêtée
++ Activating rlang global_entrace

Caused by error:
! System command 'quarto.exe' failed
Run `rlang::last_trace()` to see where the error occurred.

When quiet = TRUE, we pass --quiet to quarto render and it makes the rendering really quiet !!

> quarto render .\report.qmd --quiet
> echo $LASTEXITCODE
1
> quarto render .\report.qmd


processing file: report.qmd
  |...................................                 |  67% [unnamed-chunk-1]


Quitting from lines 8-9 [unnamed-chunk-1] (report.qmd)
Error:
! true message

Exécution arrêtée

So this is probably the same as #126 and we should indeed advice to re-run with quiet = TRUE, and even debug = TRUE to see more error

@cderv
Copy link
Collaborator

cderv commented Jan 23, 2024

After 0985e12 this is what we get (when also rlang backtrace are activated)

lines <- c(
    "---",
    "title: 'error'",
    "format: html",
    "editor: source",
    "---",
    "",
    "```{r}",
    "stop('true message')",
    "```"
)
writeLines(lines, "report.qmd")
quarto_render("report.qmd", quiet = TRUE)
#> Error in `quarto_render()`:
#> ! Error running quarto cli:
#> ℹ Rerun with `quiet = FALSE` to see the full error message.
#> Caused by error:
#> ! System command 'quarto.exe' failed
#> Backtrace:
#>     ▆
#>  1. └─quarto::quarto_render("report.qmd", quiet = TRUE)
#>  2.   └─quarto:::quarto_run(args, echo = TRUE, quarto_bin = quarto_bin) at quarto-r/R/render.R:184:3
#>  3.     └─base::tryCatch(...) at quarto-r/R/quarto.R:42:3
#>  4.       └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#>  5.         └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  6.           └─value[[3L]](cond)
#>  7.             └─rlang::abort(msg, call = .call, parent = e) at quarto-r/R/quarto.R:49:7
quarto_render("report.qmd", quiet = FALSE)
#> Error in `quarto_render()`:
#> ! Error running quarto cli:
#> ✖ ++ Activating rlang global_entrace
#> 
#> 
#> 
#> processing file: report.qmd
#>   |                                                            |                                                    |   0%  |                                                            |.................                                   |  33%                    |                                                            |...................................                 |  67% [unnamed-chunk-1]
#> 
#> 
#> Quitting from lines 8-9 [unnamed-chunk-1] (report.qmd)
#> Error:
#> ! true message
#>                                                                                                             
#> Exécution arrêtée
#> ++ Activating rlang global_entrace
#> 
#> Caused by error:
#> ! System command 'quarto.exe' failed
#> Backtrace:
#>     ▆
#>  1. └─quarto::quarto_render("report.qmd", quiet = FALSE)
#>  2.   └─quarto:::quarto_run(args, echo = TRUE, quarto_bin = quarto_bin) at quarto-r/R/render.R:184:3
#>  3.     └─base::tryCatch(...) at quarto-r/R/quarto.R:42:3
#>  4.       └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#>  5.         └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  6.           └─value[[3L]](cond)
#>  7.             └─rlang::abort(msg, call = .call, parent = e) at quarto-r/R/quarto.R:49:7

quiet = TRUE will run quarto render --quiet and this returns really nothing even when there is an error. So nothing more to show on R side from running quarto CLI.

Hope this is enough.

Feel free to ask for more otherwise.

@cderv cderv closed this as completed Jan 23, 2024
@wlandau
Copy link
Author

wlandau commented Jan 23, 2024

Thanks!

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