Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add decent error messages for wrongly used file-path-pattern #73

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

1. Fixed a bug in `samplesheetToList` that caused output mixing when the function was used more than once in channel operators.
2. Added a missing depencency for email format validation.
3. All path formats (with exception to `file-path-pattern`) will now give a proper error message when a `file-path-pattern` has been used.

## Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class FormatDirectoryPathEvaluator implements Evaluator {

// Actual validation logic
def Path file = Nextflow.file(value) as Path
if (file instanceof List) {
return Evaluator.Result.failure("'${value}' is not a directory, but a file path pattern" as String)
}
if (file.exists() && !file.isDirectory()) {
return Evaluator.Result.failure("'${value}' is not a directory, but a file" as String)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class FormatFilePathEvaluator implements Evaluator {

// Actual validation logic
def Path file = Nextflow.file(value) as Path
if (file instanceof List) {
return Evaluator.Result.failure("'${value}' is not a file, but a file path pattern" as String)
}
if (file.exists() && file.isDirectory()) {
return Evaluator.Result.failure("'${value}' is not a file, but a directory" as String)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class FormatPathEvaluator implements Evaluator {

// Actual validation logic
def Path file = Nextflow.file(value) as Path
if (file instanceof List) {
return Evaluator.Result.failure("'${value}' is not a path, but a file path pattern" as String)
}
return Evaluator.Result.success()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ class ValidateParametersTest extends Dsl2Spec{
given:
def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString()
def SCRIPT = """
params.input = 'src/testResource/samplesheet.csv'
params.input = 'src/testResources/samplesheet.csv'
params.outdir = 'src/testResources/testDir'
params.email = "[email protected]"
include { validateParameters } from 'plugin/nf-schema'
Expand All @@ -1122,7 +1122,7 @@ class ValidateParametersTest extends Dsl2Spec{
given:
def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString()
def SCRIPT = """
params.input = 'src/testResource/samplesheet.csv'
params.input = 'src/testResources/samplesheet.csv'
params.outdir = 'src/testResources/testDir'
params.email = "thisisnotanemail"
include { validateParameters } from 'plugin/nf-schema'
Expand All @@ -1145,4 +1145,56 @@ class ValidateParametersTest extends Dsl2Spec{
!stdout
}

def 'should give an error when a file-path-pattern is used with a file-path format' () {
given:
def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString()
def SCRIPT = """
params.input = 'src/testResources/*.csv'
params.outdir = 'src/testResources/testDir'
include { validateParameters } from 'plugin/nf-schema'

validateParameters(parameters_schema: '$schema')
"""

when:
def config = [:]
def result = new MockScriptRunner(config).setScript(SCRIPT).execute()
def stdout = capture
.toString()
.readLines()
.findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null }


then:
def error = thrown(SchemaValidationException)
error.message.contains("* --input (src/testResources/*.csv): 'src/testResources/*.csv' is not a file, but a file path pattern")
!stdout
}

def 'should give an error when a file-path-pattern is used with a directory-path format' () {
given:
def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString()
def SCRIPT = """
params.input = 'src/testResources/samplesheet.csv'
params.outdir = 'src/testResources/testDi*'
include { validateParameters } from 'plugin/nf-schema'

validateParameters(parameters_schema: '$schema')
"""

when:
def config = [:]
def result = new MockScriptRunner(config).setScript(SCRIPT).execute()
def stdout = capture
.toString()
.readLines()
.findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null }


then:
def error = thrown(SchemaValidationException)
error.message.contains("* --outdir (src/testResources/testDi*): 'src/testResources/testDi*' is not a directory, but a file path pattern")
!stdout
}

}
Loading