@@ -699,7 +699,7 @@ result.BatchtoolsFuture <- function(future, cleanup = TRUE, ...) {
699699} # # result()
700700
701701
702- # ' @importFrom future FutureInterruptError
702+ # ' @importFrom future FutureInterruptError FutureLaunchError
703703# ' @importFrom batchtools loadResult waitForJobs
704704# ' @importFrom utils tail
705705await <- function (future , cleanup = TRUE , ... ) {
@@ -778,8 +778,36 @@ await <- function(future, cleanup = TRUE, ...) {
778778 class(future )[1 ], label , loggedError(future ))
779779 stop(BatchtoolsFutureError(msg , future = future ))
780780 } else if (" expired" %in% stat ) {
781+ # # NOTE: If a batchtools job crashes or is killed, then it gets status
782+ # # 'expired'. In such cases, we should throw a FutureInterruptError.
783+ # #
784+ # # I think we might also see 'expired' for jobs that fail to launch,
785+ # # which in case we should throw a FutureLaunchError. I'm not sure
786+ # # how we can distinguish the two right now, but I'll assume that
787+ # # started jobs have a 'submitted' or 'started' status flag too,
788+ # # whereas jobs that failed to launch won't. /HB 2025-07-15
789+
790+ output <- loggedOutput(future )
791+ hint <- unlist(strsplit(output , split = " \n " , fixed = TRUE ))
792+ hint <- hint [nzchar(hint )]
793+ hint <- tail(hint , n = getOption(" future.batchtools.expiration.tail" , 48L ))
794+ if (length(hint ) > 0 ) {
795+ hint <- c(" The last few lines of the logged output:" , hint )
796+ hint <- paste(hint , collapse = " \n " )
797+ } else {
798+ hint <- " No logged output exist"
799+ }
800+
801+ if (any(c(" submitted" , " started" ) %in% stat )) {
802+ msg <- sprintf(" Future (%s) of class %s expired, which indicates that it crashed or was killed. %s" , label , class(future )[1 ], hint )
803+ stop(FutureInterruptError(msg , future = future ))
804+ } else {
805+ msg <- sprintf(" Future (%s) of class %s failed to launch. %s" , label , class(future )[1 ], hint )
806+ stop(FutureLaunchError(msg , future = future ))
807+ }
808+
781809 cleanup <- FALSE
782- msg <- sprintf(" BatchtoolsExpiration: Future ('%s') expired (registry path %s). " , label , reg $ file.dir )
810+ msg <- sprintf(" BatchtoolsExpiration: Future ('%s') expired (registry path %s)" , label , reg $ file.dir )
783811 output <- loggedOutput(future )
784812 hint <- unlist(strsplit(output , split = " \n " , fixed = TRUE ))
785813 hint <- hint [nzchar(hint )]
0 commit comments