futureverse / future

:rocket: R package: future: Unified Parallel and Distributed Processing in R for Everyone
https://future.futureverse.org
955 stars 85 forks source link

Bug(?) introduced in R-devel: Just a note for now - hopefully will be resolved #183

Closed HenrikBengtsson closed 6 years ago

HenrikBengtsson commented 6 years ago

Issue

On the most recent version of R-devel:

$ R --vanilla

R Under development (unstable) (2017-12-06 r73855) -- "Unsuffered Consequences"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
[...]

library("future")
plan(sequential)

try(stop("bang!"), silent = TRUE)

res <- tryCatch({ future({ warning("careful!") }) }, condition = identity)
str(res)
## List of 2
##  $ message: chr "Error in try(stop(\"bang!\"), silent = TRUE) : bang!\n"
##  $ call   : language tryCatchList(expr, classes, parentenv, handlers)
##  - attr(*, "class")= chr [1:3] "simpleError" "error" "condition"

res <- tryCatch({ future({ warning("careful!") }) }, condition = identity)
str(res)
## List of 2
##  $ message: chr "Error in try(stop(\"bang!\"), silent = TRUE) : bang!\n"
##  $ call   : language tryCatchList(expr, classes, parentenv, handlers)
##  - attr(*, "class")= chr [1:3] "simpleError" "error" "condition"

f <- future({ warning("careful!"); 42L })
## Warning message:
## In eval(quote({ : careful!
v <- value(f)
str(v)
##  int 42

res <- tryCatch({ future({ warning("careful!") }) }, condition = identity)
str(res)
## List of 2
##  $ message: chr "Error in try(stop(\"bang!\"), silent = TRUE) : bang!\n"
##  $ call   : language eval(quote({     warning("careful!") ...
##  - attr(*, "class")= chr [1:3] "simpleError" "error" "condition"

warning("woops!")
## Warning message:
## woops! 

res <- tryCatch({ future({ warning("careful!") }) }, condition = identity)
str(res)
## List of 2
##  $ message: chr "Error in try(stop(\"bang!\"), silent = TRUE) : bang!\n"
##  $ call   : language eval(quote({     warning("careful!") ...
##  - attr(*, "class")= chr [1:3] "simpleError" "error" "condition"

Note how those tryCatch() calls keeps picking up the previously generated error and not the warning produced by the future as we'd expect/get in R 3.4.3 (and all other versions of R tested):

List of 2
 $ message: chr "careful!"
 $ call   : language eval(quote({     warning("careful!") ...
 - attr(*, "class")= chr [1:3] "simpleWarning" "warning" "condition"

> warning("woops!")
Warning message:
woops! 
> res <- tryCatch({ future({ warning("careful!") }) }, condition = identity)
> str(res)
List of 2
 $ message: chr "Error in try(stop(\"bang!\"), silent = TRUE) : bang!\n"
 $ call   : language eval(quote({     warning("careful!") ...
 - attr(*, "class")= chr [1:3] "simpleError" "error" "condition"

This was caught by CRAN checks on R-devel, cf. https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-debian-gcc/future-00check.html.

Troubleshooing

I suspect this is related to R-devel SVN commit 73853 ("Preserve the error buffer when an on.exit action is processed while jumping to a calling handler. Resolves an issue reported by Bill Dunlap.") on 2017-12-06. See https://github.com/wch/r-source/commit/5f86e82f26f7066d25732ca11b48bd95ef95e63c for diff.

Futures uses on.exit() internally.

Action

I'll give it a few days before I report to R-devel / Luke T.

HenrikBengtsson commented 6 years ago

I believe the same underlying problem is also hitting future.batchtools, cf. https://cran.r-project.org/web/checks/check_results_future.batchtools.html

HenrikBengtsson commented 6 years ago

CRAN errors are going away again. Fixed in rev 73867: https://github.com/wch/r-source/commit/b851fdaa1b80c19607f4641be440c48965ceab80