Skip to content

Commit

Permalink
Allow the use of error build-in function in onComplete handler (#4458)…
Browse files Browse the repository at this point in the history
… [ci fast]



Signed-off-by: Ben Sherman <[email protected]>
Signed-off-by: Paolo Di Tommaso <[email protected]>
Co-authored-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
bentsherman and pditommaso authored Oct 30, 2023
1 parent ff8e06a commit 35a4424
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import nextflow.NextflowMeta
import nextflow.Session
import nextflow.config.ConfigBuilder
import nextflow.config.Manifest
import nextflow.exception.WorkflowScriptErrorException
import nextflow.trace.WorkflowStats
import nextflow.util.Duration
import org.codehaus.groovy.runtime.InvokerHelper
Expand Down Expand Up @@ -392,6 +393,10 @@ class WorkflowMetadata {
try {
action.call()
}
catch (WorkflowScriptErrorException e) {
// re-throw it to allow `error` function to be invoked by completion handler
throw e
}
catch (Exception e) {
log.error("Failed to invoke `workflow.onComplete` event handler", e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import java.time.OffsetDateTime

import nextflow.Const
import nextflow.Session
import nextflow.exception.WorkflowScriptErrorException
import nextflow.trace.TraceRecord
import nextflow.trace.WorkflowStats
import nextflow.trace.WorkflowStatsObserver
Expand Down Expand Up @@ -171,6 +172,24 @@ class WorkflowMetadataTest extends Specification {

}

def 'should be able to throw an error from onComplete handler' () {

given:
def session = Spy(Session)
session.getStatsObserver() >> Mock(WorkflowStatsObserver) { getStats() >> new WorkflowStats() }

def metadata = new WorkflowMetadata(session, null)

when:
metadata.onComplete {
throw new WorkflowScriptErrorException('You failed!')
}
metadata.invokeOnComplete()

then:
thrown(WorkflowScriptErrorException)
}

def 'should access workflow script variables onError' () {

given:
Expand Down

0 comments on commit 35a4424

Please sign in to comment.