Skip to content

Commit 788d936

Browse files
authored
Fix .flat ignoring an errorValue in the first map element (#640)
* Fix .flat ignoring an errorValue in the first map element * Relax .flat error tests to not match cli messages * Retain only the discriminating .flat regression test
1 parent f99c1fa commit 788d936

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
#### Updates
44

5+
* Fixes `mirai_map()` collection option `.flat` ignoring an 'errorValue' in the first element (#639).
56
* Fixes `daemon()` returning exit code 1 (idletime) instead of 2 (walltime) when `walltime` elapses while idle (#637).
67
* Fixes `race_mirai()` not waiting for resolution on compute profiles set with `url` and `dispatcher = FALSE` (#635).
78
* Fixes daemon crash for errors raised before evaluation begins (#633).
9+
* Fixes daemon cleanup not restoring options modified during evaluation (#631).
810
* `mirai_map()` dispatches tasks with lower per-element overhead.
911
* `everywhere()` dispatches with lower overhead, and errors upfront for a missing expression or invalid `...` arguments.
10-
* Fixes daemon cleanup not restoring options modified during evaluation (#631).
1112
* Ephemeral daemons return invisibly so that they do not print unnecessary output when this is being logged (thanks @jan-swissre, #619).
1213
* Requires nanonext >= 1.10.1.
1314

R/map.R

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,25 +232,26 @@ print.mirai_map <- function(x, ...) {
232232
.flat <- compiler::compile(quote(
233233
if (i == 0L) {
234234
xi <- TRUE
235-
} else if (i == 1L) {
236-
typ <<- typeof(xi)
237235
} else {
238236
is_error_value(xi) && stop_m(x, i, xi)
239-
typeof(xi) != typ &&
240-
{
241-
stop_mirai(x)
242-
cli_enabled ||
243-
stop(
244-
sprintf("Cannot flatten outputs of differing type: %s / %s", typ, typeof(xi)),
245-
call. = FALSE
237+
if (typeof(xi) != typ) {
238+
i == 1L ||
239+
{
240+
stop_mirai(x)
241+
cli_enabled ||
242+
stop(
243+
sprintf("Cannot flatten outputs of differing type: %s / %s", typ, typeof(xi)),
244+
call. = FALSE
245+
)
246+
cli::cli_abort(
247+
c(`!` = "cannot flatten outputs of differing type: {typ} / {typeof(xi)}"),
248+
location = i,
249+
name = names(x)[i],
250+
call = quote(mirai_map())
246251
)
247-
cli::cli_abort(
248-
c(`!` = "cannot flatten outputs of differing type: {typ} / {typeof(xi)}"),
249-
location = i,
250-
name = names(x)[i],
251-
call = quote(mirai_map())
252-
)
253-
}
252+
}
253+
typ <<- typeof(xi)
254+
}
254255
}
255256
))
256257

tests/tests.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ connection && {
214214
test_true(all(mres == 7L))
215215
test_null(names(mres))
216216
test_true(all(mirai_map(list(c(a = 1, b = 1, c = 1), 3), sum)[.flat] == 3))
217+
test_error(mirai_map(list("a"), function(x) x + 1L)[.flat])
217218
test_type("language", mirai_map(list(quote(1+2)), identity)[][[1]])
218219
test_class("Date", mirai_map(data.frame(x = as.Date("2020-01-01")), identity)[][[1]])
219220
test_true(is_mirai_error(mirai_map(1:2, function(x) daemons(1))[][[1]]))

0 commit comments

Comments
 (0)