From a7db332372bdec742460c44f27dd0db4fcfaa570 Mon Sep 17 00:00:00 2001 From: Ben Sherman Date: Thu, 24 Aug 2023 21:11:50 -0500 Subject: [PATCH 1/2] Fail if glob does not exist with `checkIfExists: true` Signed-off-by: Ben Sherman --- modules/nextflow/src/main/groovy/nextflow/Nextflow.groovy | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/nextflow/src/main/groovy/nextflow/Nextflow.groovy b/modules/nextflow/src/main/groovy/nextflow/Nextflow.groovy index dd1b03f8e8..89af81ad6a 100644 --- a/modules/nextflow/src/main/groovy/nextflow/Nextflow.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/Nextflow.groovy @@ -124,7 +124,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 ) { From 234079f21d2782dc88625adf1f2f5b552888c134 Mon Sep 17 00:00:00 2001 From: Ben Sherman Date: Wed, 26 Feb 2025 09:03:15 -0600 Subject: [PATCH 2/2] Add unit test Signed-off-by: Ben Sherman --- .../nextflow/src/test/groovy/nextflow/NextflowTest.groovy | 6 ++++++ 1 file changed, 6 insertions(+) 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() }