# How to stop/exit workflow?

**URL:** https://community.seqera.io/t/how-to-stop-exit-workflow/408
**Category:** Ask for help
**Created:** [January 18, 2024, 5:36pm UTC](https://community.seqera.io/t/how-to-stop-exit-workflow/408 "2024-01-18T17:36:41Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![complexgenome](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/complexgenome/32/392_2.png) [@complexgenome](https://community.seqera.io/u/complexgenome)
#### Post date: [January 18, 2024, 5:36pm UTC](https://community.seqera.io/t/how-to-stop-exit-workflow/408/1 "2024-01-18T17:36:41Z")

</div>

Hi there,  
Is there a way to stop/exit workflow after a process?  
For e.g., using exit keyword or something?

```auto
workflow wes {

def csvFile = params.input_csvFile //def csvFile = file($params.input_csvFile)
  
  Channel
        .fromPath( csvFile )
        .splitCsv( )
		.multiMap { row ->
            def tumor_reads = tuple( file( row[3]) ,file(row[4]))
            def normal_reads = tuple(file(row[1]),file(row[2]) )
            
            tumor:
                tuple( row[0], tumor_reads )
            normal:
                tuple( row[0], normal_reads )
        }
        .set { samples }
		
	FASTP(samples.tumor, samples.normal)
step2(FASTP.out)
step3(step2.out)
///exit/stop here how do I do?
step4()
step5()
step6()
step7()
step8()
step9()
step10()
}

```

I’d like to stop processing at step3 without commenting out remaining lines.  
How do I achieve it?

---

<div class="post-metadata">

### Author: ![mribeirodantas](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mribeirodantas/32/235_2.png) [@mribeirodantas](https://community.seqera.io/u/mribeirodantas)
#### Post date: [January 18, 2024, 5:47pm UTC](https://community.seqera.io/t/how-to-stop-exit-workflow/408/2 "2024-01-18T17:47:51Z")

</div>

When I’m developing a pipeline and want to see how things are going up to a certain point, I add `return` at the following line, and the pipeline will end there. It’s a useful little trick, though less valuable than live debugging with a fully powered IDE.

When talking about a proper exit during a pipeline run, there’s a Nextflow function specific to that named `error`. It’ll throw an exception. Let’s run the Nextflow pipeline below:

```Groovy
process FOO {
  debug true

  input:
  val x

  output:
  stdout

  script:
  """
  echo FOO process ${x}
  """
}

process BAR {
  debug true

  input:
  val x

  output:
  stdout

  script:
  """
  echo BAR process ${x}
  """
}

workflow {
  Channel
    .of(1..4)
    .set { my_ch }
  FOO(my_ch)
  BAR(my_ch)
}

```

The output:

 ![CleanShot 2024-01-18 at 14.49.45@2x](https://europe1.discourse-cdn.com/flex013/uploads/seqera/original/1X/503a431cac72f566a1132c20c65e92e470d2b58a.png)

Now, let’s add an `error` call before the line with `BAR(my_ch)`.

```Groovy
...

workflow {
  Channel
    .of(1..4)
    .set { my_ch }
  FOO(my_ch)
  error("Some issue occurred. A useful message here :)")
  BAR(my_ch)
}

```

Output:

 ![CleanShot 2024-01-18 at 14.49.24@2x](https://europe1.discourse-cdn.com/flex013/uploads/seqera/original/1X/52647f99060eab1b52b05dd71463096f8db8f246.png)

As you can see, though, it’s an abrupt error. It doesn’t really care what’s going on, as soon as the `error` call is evaluated, the pipeline is terminated. The best way to handle such situations is to use `errorStrategy` (more info [here](https://www.nextflow.io/docs/latest/process.html#errorstrategy)). As for skipping processes, there’s a snippet I posted earlier today that works out-of-the-box for nf-core pipelines, but can also be made to work in your own pipelines with a bit of work. Check it [here](https://community.seqera.io/t/skipping-processes-in-an-nf-core-pipeline/406).

---

<div class="post-metadata">

### Author: ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/system/32/2402_2.png) [@system](https://community.seqera.io/u/system)
#### Post date: [February 8, 2024, 3:18pm UTC](https://community.seqera.io/t/how-to-stop-exit-workflow/408/3 "2024-02-08T15:18:53Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
