Skip to content

Commit 49cd591

Browse files
authored
Fix uninformative collection errors for non-mirai errorValues (#643)
* Fix uninformative collection errors for non-mirai errorValues * Cover Interrupted and errorCondition branches of stop_m * Make cli branch test tolerant of missing rlang
1 parent 14afac5 commit 49cd591

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#### Updates
44

5+
* Fixes uninformative errors from `mirai_map()` collection when a task resolves to a non-mirai 'errorValue', e.g. cancelled or timed out (#642).
56
* Removes an ineffective promise cache from the `as.promise()` method for 'mirai_map' objects.
67
* Fixes `mirai_map()` collection option `.flat` ignoring an 'errorValue' in the first element (#639).
78
* Fixes `daemon()` returning exit code 1 (idletime) instead of 2 (walltime) when `walltime` elapses while idle (#637).

R/map.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,24 @@ mmap <- function(x, dots, envir = parent.frame()) {
311311

312312
stop_m <- function(x, i, xi) {
313313
stop_mirai(x)
314-
cli_enabled || stop(sprintf("In index %d:\n%s", i, attr(xi, "message")), call. = FALSE)
314+
msg <- if (is_mirai_error(xi)) {
315+
attr(xi, "message")
316+
} else if (is_mirai_interrupt(xi)) {
317+
"Interrupted"
318+
} else {
319+
nng_error(xi)
320+
}
321+
cli_enabled || stop(sprintf("In index %d:\n%s", i, msg), call. = FALSE)
315322
name <- names(x)[i]
316323
cli::cli_abort(
317324
c(i = "In index: {i}.", i = if (length(name) && nzchar(name)) "With name: {name}."),
318325
location = i,
319326
name = name,
320-
parent = `class<-`(attributes(xi), c("error", "condition")),
327+
parent = if (is_mirai_error(xi)) {
328+
`class<-`(attributes(xi), c("error", "condition"))
329+
} else {
330+
errorCondition(msg)
331+
},
321332
call = quote(mirai_map())
322333
)
323334
}

tests/tests.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,20 @@ connection && NOT_CRAN && {
596596
tryCatch(m[.stop], error = identity)
597597
}
598598
test_equal(info()[["connections"]], 1L)
599+
ns <- getNamespace("mirai")
600+
original_cli <- mock_binding(ns, "cli_enabled", FALSE)
601+
mp <- mirai_map(30, Sys.sleep)
602+
stop_mirai(mp)
603+
test_error(mp[.stop], "In index")
604+
mp <- mirai_map(0L, function(x) signalCondition(structure(class = c("interrupt", "condition"), list())))
605+
test_error(mp[.stop], "Interrupted")
606+
restore_binding(ns, "cli_enabled", original_cli)
607+
if (original_cli) {
608+
mp <- mirai_map(30, Sys.sleep)
609+
stop_mirai(mp)
610+
err <- tryCatch(mp[.stop], error = identity)
611+
test_true(is.null(err$parent) || is.character(conditionMessage(err$parent)))
612+
}
599613
everywhere({ assign("lk", 0L, envir = globalenv()); lockBinding("lk", globalenv()) })
600614
e <- mirai(0L, lk = 1L, .timeout = 1000)[]
601615
if (is_mirai_error(e)) test_null(e$stack.trace) else test_equal(e, 5L)

0 commit comments

Comments
 (0)