From 223b4d24917ded3cf11dff2fc5972be4d7a8f360 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Mon, 17 Feb 2025 15:50:36 +0100 Subject: [PATCH 1/9] implement a limit on the length of values in error messages --- .../main/nextflow/validation/config/ValidationConfig.groovy | 2 ++ .../nextflow/validation/validators/JsonSchemaValidator.groovy | 3 +++ 2 files changed, 5 insertions(+) diff --git a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy index c901dc1..3b137ac 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy @@ -20,6 +20,7 @@ class ValidationConfig { final public Boolean failUnrecognisedHeaders final public String parametersSchema final public Boolean showHiddenParams + final public Integer maxValueLength final public HelpConfig help final public SummaryConfig summary @@ -32,6 +33,7 @@ class ValidationConfig { failUnrecognisedParams = config.failUnrecognisedParams ?: false failUnrecognisedHeaders = config.failUnrecognisedHeaders ?: false showHiddenParams = config.showHiddenParams ?: false + maxValueLength = config.maxValueLength ?: 150 if(config.containsKey("showHiddenParams")) { log.warn("configuration option `validation.showHiddenParams` is deprecated, please use `validation.help.showHidden` or the `--showHidden` parameter instead") } diff --git a/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy b/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy index ca0b8cd..6369da7 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy @@ -65,6 +65,9 @@ public class JsonSchemaValidator { def String instanceLocation = error.getInstanceLocation() def String value = getValueFromJsonPointer(instanceLocation, rawJson) + if(value.size() > config.maxValueLength) { + value = "${value[0..(config.maxValueLength/2-1)]}...${value[-config.maxValueLength/2..-1]}" as String + } // Get the custom errorMessage if there is one and the validation errors are not about the content of the file def String schemaLocation = error.getSchemaLocation().replaceFirst(/^[^#]+/, "") From 013d52e03d3399b2c708d7235ce5e3d78611a840 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Mon, 17 Feb 2025 15:56:12 +0100 Subject: [PATCH 2/9] add an extra check to the new option --- .../validation/config/ValidationConfig.groovy | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy index 3b137ac..50548d7 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy @@ -28,12 +28,12 @@ class ValidationConfig { ValidationConfig(Map map, Map params){ def config = map ?: Collections.emptyMap() - lenientMode = config.lenientMode ?: false - monochromeLogs = config.monochromeLogs ?: false - failUnrecognisedParams = config.failUnrecognisedParams ?: false - failUnrecognisedHeaders = config.failUnrecognisedHeaders ?: false - showHiddenParams = config.showHiddenParams ?: false - maxValueLength = config.maxValueLength ?: 150 + lenientMode = config.lenientMode ?: false + monochromeLogs = config.monochromeLogs ?: false + failUnrecognisedParams = config.failUnrecognisedParams ?: false + failUnrecognisedHeaders = config.failUnrecognisedHeaders ?: false + showHiddenParams = config.showHiddenParams ?: false + maxValueLength = config.maxValueLength && config.maxValueLength >= 0 ?: 150 if(config.containsKey("showHiddenParams")) { log.warn("configuration option `validation.showHiddenParams` is deprecated, please use `validation.help.showHidden` or the `--showHidden` parameter instead") } From 9bdfc3c906b55255d40260f86b7bb064d8d348d2 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Mon, 17 Feb 2025 16:00:27 +0100 Subject: [PATCH 3/9] add an extra check to the new option --- .../src/main/nextflow/validation/config/ValidationConfig.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy index 50548d7..3b0d585 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy @@ -33,7 +33,7 @@ class ValidationConfig { failUnrecognisedParams = config.failUnrecognisedParams ?: false failUnrecognisedHeaders = config.failUnrecognisedHeaders ?: false showHiddenParams = config.showHiddenParams ?: false - maxValueLength = config.maxValueLength && config.maxValueLength >= 0 ?: 150 + maxValueLength = config.maxValueLength && config.maxValueLength >= 0 ? config.maxValueLength : 150 if(config.containsKey("showHiddenParams")) { log.warn("configuration option `validation.showHiddenParams` is deprecated, please use `validation.help.showHidden` or the `--showHidden` parameter instead") } From dee2add659106db67e9b514b263e9050f0fcbbbf Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Mon, 17 Feb 2025 16:00:33 +0100 Subject: [PATCH 4/9] update docs --- CHANGELOG.md | 1 + docs/configuration/configuration.md | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0579bd1..9af1abd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ 1. Slow uniqueness check (> 2hrs for 100k samples) made 400x faster by switching from `findAll` to a `subMap` for isolating the required unique fields. 2. `patternProperties` now has greater support, with no warnings about invalid parameters which actually match a pattern +3. Added a new configuration option: `validation.maxValueLength` which sets the maximum length that a value in an error message can be. The default is set to 150 characters. ## Changes diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 2570eb6..f59065e 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -95,6 +95,18 @@ This option does exactly the same as `validation.ignoreParams`, but provides pip validation.defaultIgnoreParams = ["param1", "param2"] // default: [] ``` +## maxValueLength + +Configure the maximum characters of a value that may be shown in an error message. It takes a whole number above or equal to `0`. A value will be truncated when it goes over the maximum amount of characters. See the below example where the limit is to 20 characters: + +``` +* --test (abcdefghij...qrstuvwxyz): Value is [string] but should be [integer] +``` + +```groovy +validation.maxValueLength = 100 // default: 150 +``` + ## help The `validation.help` config scope can be used to configure the creation of the help message. From d826c5995c7a3ca47906f888c5a202b452a6fc5f Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Mon, 17 Feb 2025 16:09:22 +0100 Subject: [PATCH 5/9] add a test --- .../validation/ValidateParametersTest.groovy | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy b/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy index 04a8f9f..f9f394b 100644 --- a/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy +++ b/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy @@ -1400,4 +1400,30 @@ class ValidateParametersTest extends Dsl2Spec{ !stdout } + def 'should truncate long values in errors' () { + given: + def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString() + def SCRIPT = """ + params.input = 'src/testResources/wrong_samplesheet_with_a_super_long_name.and_a_weird_extension' + params.outdir = 'src/testResources/testDir' + include { validateParameters } from 'plugin/nf-schema' + + validateParameters(parameters_schema: '$schema') + """ + + when: + def config = ["validation": [ + "maxValueLength": 20 + ]] + 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/testRe..._extension): \"src/testResources/wrong_samplesheet_with_a_super_long_name.and_a_weird_extension\" does not match regular expression [^\\S+\\.(csv|tsv|yaml|json)\$]") + !stdout + } } \ No newline at end of file From 38bbe273ce2e7addbf290239e0122f7509a6bff3 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Tue, 18 Feb 2025 10:29:02 +0100 Subject: [PATCH 6/9] maxValueLength -> maxErrValSize --- CHANGELOG.md | 2 +- docs/configuration/configuration.md | 4 ++-- .../main/nextflow/validation/config/ValidationConfig.groovy | 4 ++-- .../nextflow/validation/validators/JsonSchemaValidator.groovy | 4 ++-- .../test/nextflow/validation/ValidateParametersTest.groovy | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9af1abd..b640e55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ 1. Slow uniqueness check (> 2hrs for 100k samples) made 400x faster by switching from `findAll` to a `subMap` for isolating the required unique fields. 2. `patternProperties` now has greater support, with no warnings about invalid parameters which actually match a pattern -3. Added a new configuration option: `validation.maxValueLength` which sets the maximum length that a value in an error message can be. The default is set to 150 characters. +3. Added a new configuration option: `validation.maxErrValSize` which sets the maximum length that a value in an error message can be. The default is set to 150 characters. ## Changes diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index f59065e..af9800b 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -95,7 +95,7 @@ This option does exactly the same as `validation.ignoreParams`, but provides pip validation.defaultIgnoreParams = ["param1", "param2"] // default: [] ``` -## maxValueLength +## maxErrValSize Configure the maximum characters of a value that may be shown in an error message. It takes a whole number above or equal to `0`. A value will be truncated when it goes over the maximum amount of characters. See the below example where the limit is to 20 characters: @@ -104,7 +104,7 @@ Configure the maximum characters of a value that may be shown in an error messag ``` ```groovy -validation.maxValueLength = 100 // default: 150 +validation.maxErrValSize = 100 // default: 150 ``` ## help diff --git a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy index 3b0d585..fff73c1 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy @@ -20,7 +20,7 @@ class ValidationConfig { final public Boolean failUnrecognisedHeaders final public String parametersSchema final public Boolean showHiddenParams - final public Integer maxValueLength + final public Integer maxErrValSize final public HelpConfig help final public SummaryConfig summary @@ -33,7 +33,7 @@ class ValidationConfig { failUnrecognisedParams = config.failUnrecognisedParams ?: false failUnrecognisedHeaders = config.failUnrecognisedHeaders ?: false showHiddenParams = config.showHiddenParams ?: false - maxValueLength = config.maxValueLength && config.maxValueLength >= 0 ? config.maxValueLength : 150 + maxErrValSize = config.maxErrValSize && config.maxErrValSize >= 0 ? config.maxErrValSize : 150 if(config.containsKey("showHiddenParams")) { log.warn("configuration option `validation.showHiddenParams` is deprecated, please use `validation.help.showHidden` or the `--showHidden` parameter instead") } diff --git a/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy b/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy index 6369da7..c014b41 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy @@ -65,8 +65,8 @@ public class JsonSchemaValidator { def String instanceLocation = error.getInstanceLocation() def String value = getValueFromJsonPointer(instanceLocation, rawJson) - if(value.size() > config.maxValueLength) { - value = "${value[0..(config.maxValueLength/2-1)]}...${value[-config.maxValueLength/2..-1]}" as String + if(value.size() > config.maxErrValSize) { + value = "${value[0..(config.maxErrValSize/2-1)]}...${value[-config.maxErrValSize/2..-1]}" as String } // Get the custom errorMessage if there is one and the validation errors are not about the content of the file diff --git a/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy b/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy index f9f394b..890da05 100644 --- a/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy +++ b/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy @@ -1413,7 +1413,7 @@ class ValidateParametersTest extends Dsl2Spec{ when: def config = ["validation": [ - "maxValueLength": 20 + "maxErrValSize": 20 ]] def result = new MockScriptRunner(config).setScript(SCRIPT).execute() def stdout = capture From 8f4f8bc54662505209cffd6f5f7f35513154acd7 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Tue, 18 Feb 2025 10:30:17 +0100 Subject: [PATCH 7/9] set min value to 1 --- docs/configuration/configuration.md | 2 +- .../src/main/nextflow/validation/config/ValidationConfig.groovy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index af9800b..0e5ecdf 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -97,7 +97,7 @@ validation.defaultIgnoreParams = ["param1", "param2"] // default: [] ## maxErrValSize -Configure the maximum characters of a value that may be shown in an error message. It takes a whole number above or equal to `0`. A value will be truncated when it goes over the maximum amount of characters. See the below example where the limit is to 20 characters: +Configure the maximum characters of a value that may be shown in an error message. It takes a whole number above or equal to `1`. A value will be truncated when it goes over the maximum amount of characters. See the below example where the limit is to 20 characters: ``` * --test (abcdefghij...qrstuvwxyz): Value is [string] but should be [integer] diff --git a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy index fff73c1..9dbef7e 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy @@ -33,7 +33,7 @@ class ValidationConfig { failUnrecognisedParams = config.failUnrecognisedParams ?: false failUnrecognisedHeaders = config.failUnrecognisedHeaders ?: false showHiddenParams = config.showHiddenParams ?: false - maxErrValSize = config.maxErrValSize && config.maxErrValSize >= 0 ? config.maxErrValSize : 150 + maxErrValSize = config.maxErrValSize && config.maxErrValSize >= 1 ? config.maxErrValSize : 150 if(config.containsKey("showHiddenParams")) { log.warn("configuration option `validation.showHiddenParams` is deprecated, please use `validation.help.showHidden` or the `--showHidden` parameter instead") } From c4f8fb2b689d61b20e6cdb6241c065da5129e5cd Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Tue, 18 Feb 2025 11:50:41 +0100 Subject: [PATCH 8/9] add -1 as an optioni --- docs/configuration/configuration.md | 6 +++++- .../nextflow/validation/config/ValidationConfig.groovy | 10 ++++++++-- .../validation/validators/JsonSchemaValidator.groovy | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 0e5ecdf..f7997b8 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -97,7 +97,11 @@ validation.defaultIgnoreParams = ["param1", "param2"] // default: [] ## maxErrValSize -Configure the maximum characters of a value that may be shown in an error message. It takes a whole number above or equal to `1`. A value will be truncated when it goes over the maximum amount of characters. See the below example where the limit is to 20 characters: +Configure the maximum characters of a value that may be shown in an error message. It takes a whole number above or equal to `1`. A value will be truncated when it goes over the maximum amount of characters. + +Setting this option to `-1` will allow any amount of characters for values. + +See the below example where the limit is to 20 characters: ``` * --test (abcdefghij...qrstuvwxyz): Value is [string] but should be [integer] diff --git a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy index 9dbef7e..7dc6b64 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy @@ -20,7 +20,7 @@ class ValidationConfig { final public Boolean failUnrecognisedHeaders final public String parametersSchema final public Boolean showHiddenParams - final public Integer maxErrValSize + final public Integer maxErrValSize = 150 final public HelpConfig help final public SummaryConfig summary @@ -33,7 +33,13 @@ class ValidationConfig { failUnrecognisedParams = config.failUnrecognisedParams ?: false failUnrecognisedHeaders = config.failUnrecognisedHeaders ?: false showHiddenParams = config.showHiddenParams ?: false - maxErrValSize = config.maxErrValSize && config.maxErrValSize >= 1 ? config.maxErrValSize : 150 + if(config.maxErrValSize != null) { + if(config.maxErrValSize >= 1 || config.maxErrValSize == -1) { + maxErrValSize = config.maxErrValSize + } else { + log.warn("`validation.maxErrValSize` needs to be a value above 0 or equal to -1, defaulting to ${maxErrValSize}") + } + } if(config.containsKey("showHiddenParams")) { log.warn("configuration option `validation.showHiddenParams` is deprecated, please use `validation.help.showHidden` or the `--showHidden` parameter instead") } diff --git a/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy b/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy index c014b41..6c12045 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/validators/JsonSchemaValidator.groovy @@ -65,7 +65,7 @@ public class JsonSchemaValidator { def String instanceLocation = error.getInstanceLocation() def String value = getValueFromJsonPointer(instanceLocation, rawJson) - if(value.size() > config.maxErrValSize) { + if(config.maxErrValSize >= 1 && value.size() > config.maxErrValSize) { value = "${value[0..(config.maxErrValSize/2-1)]}...${value[-config.maxErrValSize/2..-1]}" as String } From 8fd073c7facbbf16f1bd9f8a6f2defbe0392d727 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Tue, 18 Feb 2025 11:54:02 +0100 Subject: [PATCH 9/9] prettier --- docs/configuration/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index f7997b8..2fa99b7 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -97,7 +97,7 @@ validation.defaultIgnoreParams = ["param1", "param2"] // default: [] ## maxErrValSize -Configure the maximum characters of a value that may be shown in an error message. It takes a whole number above or equal to `1`. A value will be truncated when it goes over the maximum amount of characters. +Configure the maximum characters of a value that may be shown in an error message. It takes a whole number above or equal to `1`. A value will be truncated when it goes over the maximum amount of characters. Setting this option to `-1` will allow any amount of characters for values.