joost
joost

Reputation: 149

How to call a process in workflow.onError

I have this small pipeline:


process test {
    """
    echo 'hello'
    exit 1
    """
}

workflow.onError {
    process finish_error{
        script:
        """
        echo 'blablabla'
        """
    }
}

I want to trigger a python script in case the pipeline has an error using the finish error process, but this entire process does not seem to be triggered even when using a simple echo blabla example.

nextflow run test.nf 
N E X T F L O W  ~  version 20.10.0
Launching `test.nf` [cheesy_banach] - revision: 9020d641ca
executor >  local (1)
[56/994298] process > test         [100%] 1 of 1, failed: 1 ✘
[-        ] process > finish_error [  0%] 0 of 1
Error executing process > 'test'

Caused by:
  Process `test` terminated with an error exit status (1)

Command executed:

  echo 'hello'
  exit 1

Command exit status:
  1

Command output:
  hello

Command wrapper:
  hello

Work dir:
  /home/joost/nextflow/work/56/9942985fc9948fd9bf7797d39c1785

Tip: when you have fixed the problem you can continue the execution adding the option `-resume` to the run command line

How can I trigger this finish_error process, and how can I view its output?

Upvotes: 1

Views: 702

Answers (1)

Steve
Steve

Reputation: 54402

The onError handler is invoked when a process causes pipeline execution to terminate prematurely. Since a Nextflow pipeline is really just a series of processes joined together, launching another pipeline process from within an event handler doesn't make much sense to me. If your python script should be run using the local executor, you can just execute it in the usual way. This example assumes your script is executable and has an appropriate shebang:

process test {

    """
    echo 'hello'
    exit 1
    """
}

workflow.onError {

    def proc = "${baseDir}/test.py".execute()
    proc.waitFor()

    println proc.text
}

Run using:

nextflow run -ansi-log false test.nf 

Upvotes: 1

Related Questions