Skip to content

Commit ed47e44

Browse files
committed
Polish parallel errors
1 parent a930f5c commit ed47e44

File tree

8 files changed

+29
-17
lines changed

8 files changed

+29
-17
lines changed

β€ŽR/parallel-taskq.Rβ€Ž

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ task_q <- R6::R6Class(
206206
},
207207

208208
handle_error = function(msg, task_no) {
209-
cli::cli_inform("") # get out of the progress bar, if any
209+
cat("\n") # get out of the progress bar, if any
210210
fun <- private$tasks$fun[[task_no]]
211211
file <- private$tasks$args[[task_no]][[1]]
212212
if (is.null(fun)) {
@@ -218,18 +218,19 @@ task_q <- R6::R6Class(
218218
cli::cli_abort(
219219
c(
220220
"testthat subprocess failed to start.",
221-
"i" = "stderr: {msg$error$stderr}"
221+
" " = "{no_wrap(msg$error$stderr)}"
222222
),
223223
test_file = NULL,
224-
parent = msg$error,
225-
class = c("testthat_process_error", "testthat_error")
224+
class = c("testthat_process_error", "testthat_error"),
225+
call = NULL
226226
)
227227
} else {
228228
cli::cli_abort(
229229
"testthat subprocess exited in file {.file {file}}.",
230230
test_file = file,
231231
parent = msg$error,
232-
class = c("testthat_process_error", "testthat_error")
232+
class = c("testthat_process_error", "testthat_error"),
233+
call = NULL
233234
)
234235
}
235236
}

β€ŽR/snapshot-value.Rβ€Ž

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,10 @@ check_roundtrip <- function(
116116
tolerance = tolerance
117117
)
118118
if (length(check) > 0) {
119-
# Supress cli wrapping
120-
check <- gsub(" ", "\u00a0", check, fixed = TRUE)
121-
check <- gsub("\n", "\f", check, fixed = TRUE)
122-
123119
cli::cli_abort(
124120
c(
125121
"{.code {label}} could not be safely serialized with {.arg style} = {.str {style}}.",
126-
" " = "Serializing then deserializing the object returned something new:\n\n{check}\n",
122+
" " = "Serializing then deserializing the object returned something new:\n\n{no_wrap(check)}\n",
127123
i = "You may need to try a different {.arg style}."
128124
),
129125
call = error_call

β€ŽR/source.Rβ€Ž

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ source_file <- function(
6464
invisible(eval(exprs, env)),
6565
error = function(err) {
6666
cli::cli_abort(
67-
"In path: {.path {path}}.",
67+
"Failed to evaluate {.path {path}}.",
6868
parent = err,
6969
call = error_call
7070
)
@@ -128,9 +128,17 @@ source_dir <- function(
128128
chdir = TRUE,
129129
wrap = TRUE
130130
) {
131-
files <- normalizePath(sort(dir(path, pattern, full.names = TRUE)))
131+
files <- sort(dir(path, pattern, full.names = TRUE))
132+
133+
error_call <- current_env()
132134
lapply(files, function(path) {
133-
source_file(path, env = env, chdir = chdir, wrap = wrap)
135+
source_file(
136+
path,
137+
env = env,
138+
chdir = chdir,
139+
wrap = wrap,
140+
error_call = error_call
141+
)
134142
})
135143
}
136144

β€ŽR/utils.Rβ€Ž

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,10 @@ in_rcmd_check <- function() {
5656
}
5757

5858
r_version <- function() paste0("R", getRversion()[, 1:2])
59+
60+
# Supress cli wrapping
61+
no_wrap <- function(x) {
62+
x <- gsub(" ", "\u00a0", x, fixed = TRUE)
63+
x <- gsub("\n", "\f", x, fixed = TRUE)
64+
x
65+
}

β€Žtests/testthat/_snaps/source.mdβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
source_file(test_path("reporters/error-setup.R"), wrap = FALSE)
55
Condition
66
Error:
7-
! In path: 'reporters/error-setup.R'.
7+
! Failed to evaluate 'reporters/error-setup.R'.
88
Caused by error in `h()`:
99
! !
1010

β€Žtests/testthat/test-parallel-setup.Rβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ test_that("error in parallel setup code", {
99
error = function(e) e
1010
)
1111
expect_s3_class(err, "testthat_process_error")
12-
expect_match(err$message, "Error in setup", fixed = TRUE)
12+
expect_match(conditionMessage(err), "Error in setup", fixed = TRUE)
1313
})

β€Žtests/testthat/test-parallel-startup.Rβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ test_that("startup error", {
99
error = function(e) e
1010
)
1111
expect_s3_class(err, "testthat_process_error")
12-
expect_match(err$message, "This will fail", fixed = TRUE)
12+
expect_match(conditionMessage(err), "This will fail", fixed = TRUE)
1313
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.onLoad <- function(libname, pkgname) {
2-
stop("This will fail when loading the package")
2+
stop("This will fail when loading the package", call. = FALSE)
33
}

0 commit comments

Comments
Β (0)