diff --git a/modules/nextflow/src/main/groovy/nextflow/Nextflow.groovy b/modules/nextflow/src/main/groovy/nextflow/Nextflow.groovy index e7dc15884c..aee6368755 100644 --- a/modules/nextflow/src/main/groovy/nextflow/Nextflow.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/Nextflow.groovy @@ -135,7 +135,11 @@ class Nextflow { } // revolve the glob pattern returning all matches - return fileNamePattern(splitter, options) + final result = fileNamePattern(splitter, options) + if( glob && options?.checkIfExists && result.isEmpty() ) + throw new NoSuchFileException(path.toString()) + + return result } static files( Map options=null, def path ) { diff --git a/modules/nextflow/src/test/groovy/nextflow/NextflowTest.groovy b/modules/nextflow/src/test/groovy/nextflow/NextflowTest.groovy index f49db65779..4eda38c9a9 100644 --- a/modules/nextflow/src/test/groovy/nextflow/NextflowTest.groovy +++ b/modules/nextflow/src/test/groovy/nextflow/NextflowTest.groovy @@ -348,6 +348,12 @@ class NextflowTest extends Specification { def e = thrown(NoSuchFileException) e.message == foo.toString() + when: + Nextflow.file("$folder/*.txt", checkIfExists: true) + then: + e = thrown(NoSuchFileException) + e.message == "$folder/*.txt" + cleanup: folder?.deleteDir() }