Skip to content

Commit

Permalink
Lift error handler to chunk level
Browse files Browse the repository at this point in the history
Signed-off-by: eternal-flame-AD <[email protected]>
  • Loading branch information
eternal-flame-AD committed Oct 11, 2024
1 parent 1017891 commit 034f88d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
12 changes: 1 addition & 11 deletions R/block.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ eng_r = function(options) {
} else if (cache.exists && isFALSE(options$cache.rebuild)) {
cache$output(options$hash, 'list')
} else in_input_dir(
withCallingHandlers(
evaluate(
code, envir = env, new_device = FALSE,
keep_warning = if (is.numeric(options$warning)) TRUE else options$warning,
Expand All @@ -268,16 +267,7 @@ eng_r = function(options) {
if (options$error && options$include) 0L else 2L
},
output_handler = knit_handlers(options$render, options)
),
error = function (cnd) {
if (xfun::pkg_available('rlang', '1.0.0')) {
rlang::abort(paste0("Error in chunk ", options$label), parent = cnd)
} else {
signalCondition(cnd)
stop(cnd)
}
}
)
)
)
if (options$cache %in% 1:2 && (!cache.exists || isTRUE(options$cache.rebuild))) {
# make a copy for cache=1,2; when cache=2, we do not really need plots
Expand Down
19 changes: 8 additions & 11 deletions R/output.R
Original file line number Diff line number Diff line change
Expand Up @@ -308,18 +308,15 @@ process_file = function(text, output) {
if (progress && is.function(pb$update)) pb$update(i)
group = groups[[i]]
knit_concord$set(block = i)
res[i] = xfun:::handle_error(
withCallingHandlers(
res[i] = withCallingHandlers(
if (tangle) process_tangle(group) else process_group(group),
error = function(e) if (xfun::pkg_available('rlang', '1.0.0')) rlang::entrace(e)
),
function(loc) {
setwd(wd)
write_utf8(res, output %n% stdout())
paste0('\nQuitting from lines ', loc)
},
if (labels[i] != '') sprintf(' [%s]', labels[i]), get_loc
)
error = function(cnd) {
setwd(wd)
write_utf8(res, output %n% stdout())
loc <- if (labels[i] != '') get_loc(sprintf(' [%s]', labels[i])) else ''
rlang::abort(paste0('Quitting from lines ', loc), parent = cnd)
}
)
}

if (!tangle) res = insert_header(res) # insert header
Expand Down

0 comments on commit 034f88d

Please sign in to comment.