From 45bb0f3596c50115547c33907d159aa2231d084b Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Wed, 8 Jan 2025 22:46:56 -0600 Subject: [PATCH] interrupt the progress bar on error by adding \n (to stderr) so that the error message can be displayed on a new line (#2387) --- R/output.R | 5 ++++- R/utils.R | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/R/output.R b/R/output.R index 59414d894d..f3960b597b 100644 --- a/R/output.R +++ b/R/output.R @@ -311,7 +311,10 @@ process_file = function(text, output) { res[i] = xfun:::handle_error( withCallingHandlers( if (tangle) process_tangle(group) else process_group(group), - error = function(e) if (xfun::pkg_available('rlang', '1.0.0')) rlang::entrace(e) + error = function(e) { + if (progress && is.function(pb$interrupt)) pb$interrupt() + if (xfun::pkg_available('rlang', '1.0.0')) rlang::entrace(e) + } ), function(loc) { setwd(wd) diff --git a/R/utils.R b/R/utils.R index 3fdf1f120e..7add5f0976 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1136,6 +1136,7 @@ txt_pb = function(total, labels) { setTxtProgressBar(pb, i) cat_line(s[i]) # append chunk label to the progress bar }, + interrupt = function() message('\n'), done = function() { # wipe the progress bar cat_line('\r', strrep(' ', max(w2, 10) + 10 + n))