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

Print param name when path does not exist #65

Merged
merged 5 commits into from
Jul 7, 2023
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
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())
ewels marked this conversation as resolved.
Show resolved Hide resolved
}
} 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