knitr capture reports every chunk error as rlang_error (knitr wraps errors via rlang::entrace)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 55/100
Direzione di ricerca
Start with crates/quarto-core/src/engine/knitr/resources/rmd/capture.R:150 and the failing test crates/quarto-core/src/engine/knitr/capture_tests.rs:170; trace how the captured condition supplies its class and error details. Run the reproduction command with R, knitr, rmarkdown, jsonlite, and rlang installed. Done means captured errors retain the original class, with tests covering ordinary and custom errors; the issue also leaves the desired error text and R-enabled CI coverage for discussion.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
When rlang is installed, knitr runs every chunk error through rlang::entrace(). That function wraps the original error in a new condition of class rlang_error. Our knitr capture code (crates/quarto-core/src/engine/knitr/resources/rmd/capture.R:150) records ename = class(p)[[1]], so every captured error is reported as rlang_error. The user's actual class, such as simpleError or a custom class, is lost.
Since rlang is installed in almost every real R setup, this affects most users.
Reproduction
With R, knitr, rmarkdown, jsonlite and rlang installed:
cargo nextest run -p quarto-core --lib -E 'test(knitr::capture_tests::capture_classifies_pieces)'
panicked at crates/quarto-core/src/engine/knitr/capture_tests.rs:170:13:
assertion `left == right` failed
left: "rlang_error"
right: "simpleError"
Fails with both:
- R 4.6.0, knitr 1.51, rlang 1.2.0, evaluate 1.0.5
- R 4.6.0, knitr 1.52, rlang 1.3.0, evaluate 1.0.5 (latest CRAN as of 2026-11-09)
Cause
knitr:::knit_handlers appends rlang_entrace_handler (list(error = function(e) rlang::entrace(e))) to the chunk's calling_handlers whenever knitr:::has_rlang is TRUE. Reproduced with evaluate alone:
h <- evaluate::new_output_handler(
calling_handlers = list(error = function(e) rlang::entrace(e)))
e <- evaluate::evaluate('stop("boom")', output_handler = h)[[2]]
class(e) # "rlang_error" "error" "condition"
class(e$error) # "simpleError" "error" "condition"
A custom error class is also replaced: with stop(structure(class = c("myError", "error", "condition"), ...)), class(e) is rlang_error and class(e$error) is myError.
Suggested fix
In capture.R, when p inherits from rlang_error and has an $error field, read ename from class(p$error)[[1]]. Otherwise fall back to class(p)[[1]]. Then decide whether evalue and call should also come from p$error.
A related question: knitr also changes the error text to rlang's format (Error:\n! boom instead of Error in …: boom). The test only checks starts_with("Error"), so it still passes, but we should decide whether that text is what we want to show.
Why CI didn't catch this
No CI workflow installs R, and every test in capture_tests.rs skips itself through r_available() when R is missing. These tests therefore only run on developer machines that have R. It's worth adding R (with knitr and rlang) to at least one CI leg.
Found while investigating pandoc 3.13 test failures; this failure is unrelated to pandoc.
- Lingua principale
- Rust
- Stelle
- 302
- Fork
- 22
- Merge medio
- 5h 8m
- PR unite (30g)
- 220
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di quarto-dev/q2
-
`q2 render` ignores `NO_COLOR` and prints colour codes and hyperlinks in its diagnosticsForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
quarto-dev/q2#1135 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
quarto-dev/q2#1133 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
quarto-dev/q2#1103 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
quarto-dev/q2#1095 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
quarto-dev/q2#1031 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di quarto-dev/q2
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
area:cli kind:docs prio:low
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
DecapodLabs/decapod#1626 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno