Skip to content

Commit

Permalink
close #2141: show the inline code in the error message, so that users…
Browse files Browse the repository at this point in the history
… can find it more easily in the source document
  • Loading branch information
yihui committed Jun 14, 2022
1 parent 907184f commit 3cbf47f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: knitr
Type: Package
Title: A General-Purpose Package for Dynamic Report Generation in R
Version: 1.39.3
Version: 1.39.4
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),
person("Abhraneel", "Sarma", role = "ctb"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## MINOR CHANGES

- When the inline R code cannot be correctly parsed, the error message will show the original code in addition to the parsing error, which can make it easier to identify the code error in the source document (thanks, @AlbertLei, #2141).

- The internal function `knitr:::wrap()` has been removed from this package. If you rely on this function, you will have to use the exported function `knitr::sew()` instead.

- Duplicate chunk label error will now be thrown with code chunks using `code` or `file` chunk options (thanks, @mine-cetinkaya-rundel, #2126).
Expand Down
4 changes: 3 additions & 1 deletion R/hooks.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
message = .out.hook, error = .out.hook, plot = .plot.hook,
inline = .inline.hook, chunk = .out.hook, text = identity,
evaluate.inline = function(code, envir = knit_global()) {
v = withVisible(eval(parse_only(code), envir = envir))
v = withVisible(eval(tryCatch(parse_only(code), error = function(e) {
stop2('Failed to parse the inline R code: ', code, ' (Reason: ', e$message, ')')
}), envir = envir))
if (v$visible) knit_print(v$value, inline = TRUE, options = opts_chunk$get())
},
evaluate = function(...) evaluate::evaluate(...), document = identity
Expand Down

0 comments on commit 3cbf47f

Please sign in to comment.