You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The original error produced while evaluating an expression on a background PSOCK cluster is not accessible to the master process. Instead, only a regenerated 'simpleError' with the same condtional message is produced and available in the master process.
Example
library("parallel")
cl<- makeCluster(1L, type="PSOCK")
print(class(cl))
# [1] "SOCKcluster" "cluster"res<- tryCatch(clusterEvalQ(cl, {
stop("boom")
}), error=identity)
print(res)
# <simpleError in checkForRemoteErrors(lapply(cl, recvResult)): one node produced an error: boom>
print(class(res))
# [1] "simpleError" "error" "condition"
stopifnot(inherits(res, "error"), inherits(res, "simpleError"))
>res<- tryCatch(clusterEvalQ(cl, {
+ stop(structure(list(message="boom"), class= c("MyError", "error", "condition")))
+ }), error=identity)
print(res)
# <simpleError in checkForRemoteErrors(lapply(cl, recvResult)): 2 nodes produced errors; first error: boom>
print(class(res))
# [1] "simpleError" "error" "condition"
str(res)
# List of 2# $ message: chr "2 nodes produced errors; first error: boom"# $ call : language checkForRemoteErrors(lapply(cl, recvResult))# - attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
stopifnot(inherits(res, "error"), inherits(res, "MyError")) ## <== THIS FAILS!# Error: inherits(res, "MyError") is not TRUE
stopCluster(cl)
checkForRemoteErrors<-function(val)
{
count<-0checkForRemoteErrors<-function(val)
{
count<-0firstmsg<-NULLfor (vinval) {
if (inherits(v, "try-error")) {
count<-count+1if (count==1) firstmsg<-v
}
}
## These will not translateif (count==1)
stop("one node produced an error: ", firstmsg, domain=NA)
elseif (count>1)
stop(count, " nodes produced errors; first error: ", firstmsg, domain=NA)
val
}
firstmsg<-NULLfor (vinval) {
if (inherits(v, "try-error")) {
count<-count+1if (count==1) firstmsg<-v
}
}
## These will not translateif (count==1)
stop("one node produced an error: ", firstmsg, domain=NA)
elseif (count>1)
stop(count, " nodes produced errors; first error: ", firstmsg, domain=NA)
val
}
However, since the transferred error is of class try-error, the original error should be available in attribute "condition", e.g.
## This uses the message rather than the exception since## the exception class/methods may not be available on the## master.handler<-function(e) {
success<<-FALSE
structure(conditionMessage(e),
class= c("snow-try-error","try-error"))
}
That source code comment also explains that this is not a mistake but a deliberate decision. However, it wouldn't hurt to at least to pass it along.
Issue
The original error produced while evaluating an expression on a background PSOCK cluster is not accessible to the master process. Instead, only a regenerated 'simpleError' with the same condtional message is produced and available in the master process.
Example
Troubleshooting
This is because the error that is regenerated with the original message but without preserving the original error object:
However, since the transferred error is of class
try-error
, the original error should be available in attribute "condition", e.g.EDIT 2018-02-21: There was a typo in my code resulting in invalid error objects.
The text was updated successfully, but these errors were encountered: