Skip to content

module run crashes with "Cannot access first() element from an empty List" when process has empty optional outputs #6978

@pditommaso

Description

@pditommaso

Bug report

Description

nextflow module run crashes with NoSuchElementException: Cannot access first() element from an empty List when running a module whose process has optional output channels that produce no files. The underlying process task completes successfully (exit code 0), but the error occurs during the output publishing phase in PublishOp.onComplete.

Version

  • Nextflow: 26.03.0-edge build 0
  • System: Mac OS X 26.3.1
  • Runtime: Groovy 4.0.30 on OpenJDK 64-Bit Server VM 21+35

Command used

nextflow module run nf-core/trimgalore \
    --meta.id test_sample \
    --reads "reads_1.fastq.gz,reads_2.fastq.gz" \
    --outdir results_trimgalore

Error output

[PIPELINE] main.nf | profile=standard
[WORKDIR] /Users/pditommaso/Projects/nextflow/test-modules/work
[PROCESS 13/39f78a] TRIMGALORE (test_sample)
[ERROR] ERROR ~ Cannot access first() element from an empty List

 -- Check '.module.log' file for details

[FAILED] completed=1 failed=0 cached=0

Debug log (.module.log)

The relevant lines from the debug log:

[TaskFinalizer] DEBUG nextflow.processor.TaskProcessor - Process TRIMGALORE > Skipping output binding because one or more optional files are missing: fileoutparam<2:1>
[TaskFinalizer] DEBUG nextflow.processor.TaskProcessor - Process TRIMGALORE > Skipping output binding because one or more optional files are missing: fileoutparam<3:1>
[TaskFinalizer] DEBUG nextflow.processor.TaskProcessor - Process TRIMGALORE > Skipping output binding because one or more optional files are missing: fileoutparam<4:1>
[main] ERROR nextflow.Session - Cannot access first() element from an empty List
java.util.NoSuchElementException: Cannot access first() element from an empty List
	at org.codehaus.groovy.runtime.DefaultGroovyMethods.first(DefaultGroovyMethods.java:10343)
	at nextflow.extension.PublishOp.onComplete(PublishOp.groovy:221)
	at nextflow.extension.PublishOp$_apply_closure2$_closure7.doCall(PublishOp.groovy:78)
	at nextflow.extension.PublishOp.safeExecute(PublishOp.groovy:94)
	at nextflow.extension.PublishOp$_apply_closure2.doCall(PublishOp.groovy:78)
	at nextflow.extension.DataflowHelper$3.afterStop(DataflowHelper.groovy:257)
	...

Analysis

The nf-core/trimgalore module defines several optional output channels (zip, html, unpaired) that may not produce files depending on the run parameters. When these optional outputs emit no files:

  1. The task itself completes successfully (exit 0, trimmed reads are produced)
  2. The output binding step correctly skips the missing optional files
  3. But PublishOp.onComplete() at line 221 calls .first() on an empty list, causing the crash

Expected behavior

nextflow module run should handle empty optional output channels gracefully and complete successfully, publishing only the outputs that were produced (in this case: reads, log, and versions_trimgalore).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions