Skip to content

Commit

Permalink
Don't "force unhandled errors" as a matter of course
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Aug 10, 2020
1 parent 9594ee9 commit 23a3462
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
13 changes: 12 additions & 1 deletion R/reprex.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' reprex can also be used for syntax highlighting (with or without rendering);
#' see below for more.
#'
#' @section Details:
#' @details
#' The usual "code + commented output" is returned invisibly, put on the
#' clipboard, and written to file. An HTML preview displays in RStudio's Viewer
#' pane, if available, or in the default browser, otherwise. Leading `"> "`
Expand Down Expand Up @@ -48,6 +48,17 @@
#' discussed in [an
#' article](https://reprex.tidyverse.org/articles/articles/rtf.html)
#'
#' @section Backtraces:
#' The functions `rlang::last_error()` and `rlang::last_trace()` do not work the
#' same inside `reprex()` as they do in an interactive session. This is outside
#' the scope of the reprex package and should get resolved by future changes in
#' the evaluate package. In the meantime, enable these functions in a specific
#' reprex by setting an rlang option *in the code snippet* you are reprexing:
#'
#' ```
#' options("rlang:::force_unhandled_error" = TRUE)
#' ````
#'
#' @param x An expression. If not given, `reprex()` looks for code in
#' `input` or on the clipboard, in that order.
#' @param input Character. If has length one and lacks a terminating newline,
Expand Down
4 changes: 3 additions & 1 deletion R/reprex_render.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ reprex_render_impl <- function(input,
opts <- list(
keep.source = TRUE,
rlang_trace_top_env = globalenv(),
`rlang:::force_unhandled_error` = TRUE,
# https://github.com/tidyverse/reprex/issues/320
# TL;DR Inline this, as needed. Real fix needs to happen in evaluate.
#`rlang:::force_unhandled_error` = TRUE,
rlang_backtrace_on_error = "full",
crayon.enabled = FALSE
)
Expand Down
14 changes: 11 additions & 3 deletions man/reprex.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/testthat/test-reprex.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ test_that("rmarkdown::render() context is trimmed from rlang backtrace", {
expect_false(any(grepl("rmarkdown::render", ret)))
})

test_that("rlang::last_error() and last_trace() work", {
test_that("rlang::last_error() and last_trace() can work", {
skip_on_cran()

input <- c(
"options('rlang:::force_unhandled_error' = TRUE)",
"f <- function() rlang::abort('foo')",
"f()",
"rlang::last_error()",
Expand Down

0 comments on commit 23a3462

Please sign in to comment.