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

Auto-entrace errors #231

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion R/evaluate.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
),
eval_continue = function() TRUE,
eval_stop = function() FALSE,
eval_error = function(cnd) {signalCondition(cnd); stop(cnd)}
eval_error = signal_error
)
watcher$check_devices()

Expand All @@ -167,6 +167,14 @@
watcher$get()
}

signal_error <- function(cnd) {
signalCondition(cnd)
if (has_rlang) {
cnd <- rlang::cnd_entrace(cnd)

Check warning on line 173 in R/evaluate.R

View check run for this annotation

Codecov / codecov/patch

R/evaluate.R#L172-L173

Added lines #L172 - L173 were not covered by tests
}
stop(cnd)

Check warning on line 175 in R/evaluate.R

View check run for this annotation

Codecov / codecov/patch

R/evaluate.R#L175

Added line #L175 was not covered by tests
}

check_stop_on_error <- function(x) {
if (is.numeric(x) && length(x) == 1 && !is.na(x)) {
if (x == 0L) {
Expand Down
4 changes: 4 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
# used by knitr, as above, but also for value handler
default_output_handler <- NULL

has_rlang <- FALSE

.onLoad <- function(...) {
evaluate_default_output_handler <<- new_output_handler()
default_output_handler <<- new_output_handler()
# Match knitr's expectations
default_output_handler$value <<- function(x) {
render(x, visible = TRUE, envir = parent.frame())
}

has_rlang <<- requireNamespace("rlang", quietly = TRUE)

Check warning on line 16 in R/zzz.R

View check run for this annotation

Codecov / codecov/patch

R/zzz.R#L16

Added line #L16 was not covered by tests
}
Loading