Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #65 from mirpedrol/path-missing-param
Browse files Browse the repository at this point in the history
Print param name when path does not exist
  • Loading branch information
mirpedrol authored Jul 7, 2023
2 parents 8c16c6d + 95ee116 commit 62a283e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
- Only validate a file with a schema if the file path is provided ([#51](https://github.com/nextflow-io/nf-validation/pull/51))
- Handle errors when sample sheet not provided or doesn't have a schema ([#56](https://github.com/nextflow-io/nf-validation/pull/56))
- Silently ignore samplesheet fields that are not defined in samplesheet schema ([#59](https://github.com/nextflow-io/nf-validation/pull/59))
- Correctly handle double-quoted fields containing commas in csv files by `.fromSamplesheet()` [#63](https://github.com/nextflow-io/nf-validation/pull/63))
- Correctly handle double-quoted fields containing commas in csv files by `.fromSamplesheet()` ([#63](https://github.com/nextflow-io/nf-validation/pull/63))
- Print param name when path does not exist ([#65](https://github.com/nextflow-io/nf-validation/pull/65))
- Fix file or directory does not exist error not printed when it was the only error in a samplesheet ([#65](https://github.com/nextflow-io/nf-validation/pull/65))
- Do not return parameter in summary if it has no default in the schema and is set to 'false' ([#66](https://github.com/nextflow-io/nf-validation/pull/66))

## Version 0.2.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class SchemaValidator extends PluginExtensionPoint {
def List<String> pathsToCheck = (List) collectExists(schemaParams)
pathsToCheck.each {
if (params[it] != null) {
pathExists(params[it].toString())
pathExists(params[it].toString(), it.toString())
}
}

Expand Down Expand Up @@ -510,12 +510,11 @@ class SchemaValidator extends PluginExtensionPoint {
//=====================================================================//
// Check if files or directories exist
def List<String> pathsToCheck = (List) collectExists(schemaParams)
pathsToCheck.each { fieldName ->
def String filedName = fieldName
pathsToCheck.each { String fieldName ->
for (int i=0; i < arrayJSON.size(); i++) {
def JSONObject entry = arrayJSON.getJSONObject(i)
if ( entry.has(filedName) ) {
pathExists(entry[filedName].toString())
if ( entry.has(fieldName) ) {
pathExists(entry[fieldName].toString(), " Entry ${(i+1).toString()} - ${fieldName.toString()}")
}
}
}
Expand All @@ -528,6 +527,13 @@ class SchemaValidator extends PluginExtensionPoint {
.primitiveValidationStrategy(PrimitiveValidationStrategy.LENIENT)
.build();
validator.performValidation(schema, arrayJSON);
if (this.hasErrors()) {
// Needed for custom errors such as pathExists() errors
def colors = logColours(monochrome_logs)
def msg = "${colors.red}The following errors have been detected:\n\n" + this.getErrors().join('\n').trim() + "\n${colors.reset}\n"
log.error("ERROR: Validation of '$paramName' file failed!")
throw new SchemaValidationException(msg, this.getErrors())
}
} catch (ValidationException e) {
def colors = logColours(monochrome_logs)
JSONObject exceptionJSON = (JSONObject) e.toJSON()
Expand All @@ -546,10 +552,10 @@ class SchemaValidator extends PluginExtensionPoint {
//
// Function to check if a file or directory exists
//
List pathExists(String path) {
List pathExists(String path, String paramName) {
def Path file = Nextflow.file(path) as Path
if (!file.exists()) {
errors << "* The file or directory '${path}' does not exist.".toString()
errors << "* --${paramName}: the file or directory '${path}' does not exist.".toString()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ class SamplesheetConverterTest extends Dsl2Spec{
def error = thrown(SchemaValidationException)
def errorMessages = error.message.readLines()
errorMessages[0] == "\033[0;31mThe following errors have been detected:"
errorMessages[2] == "* The file or directory 'non_existing_path' does not exist."
errorMessages[3] == "* The file or directory 'non_existing_file.tsv' does not exist."
errorMessages[2] == "* -- Entry 1 - field_9: the file or directory 'non_existing_path' does not exist."
errorMessages[3] == "* -- Entry 1 - field_7: the file or directory 'non_existing_file.tsv' does not exist."
errorMessages[4] == '* -- Entry 1 - field_7: string [non_existing_file.tsv] does not match pattern ^.*\\.txt$ (non_existing_file.tsv)'
errorMessages[5] == "* -- Entry 1 - field_8: 'src/testResources/test.txt' is not a directory, but a file (src/testResources/test.txt)"
errorMessages[6] == "* -- Entry 1 - field_5: expected type: Number, found: String (string)"
Expand Down

0 comments on commit 62a283e

Please sign in to comment.