diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d0ff5d5..210f191e 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.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 2570eb6f..2fa99b77 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -95,6 +95,22 @@ This option does exactly the same as `validation.ignoreParams`, but provides pip 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. + +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] +``` + +```groovy +validation.maxErrValSize = 100 // default: 150 +``` + ## help The `validation.help` config scope can be used to configure the creation of the help message. 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 c901dc15..7dc6b64e 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 maxErrValSize = 150 final public HelpConfig help final public SummaryConfig summary @@ -27,11 +28,18 @@ 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 + lenientMode = config.lenientMode ?: false + monochromeLogs = config.monochromeLogs ?: false + failUnrecognisedParams = config.failUnrecognisedParams ?: false + failUnrecognisedHeaders = config.failUnrecognisedHeaders ?: false + showHiddenParams = config.showHiddenParams ?: false + 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 ca0b8cd2..6c12045d 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(config.maxErrValSize >= 1 && 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 def String schemaLocation = error.getSchemaLocation().replaceFirst(/^[^#]+/, "") diff --git a/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy b/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy index 9d04ce7f..513c60c7 100644 --- a/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy +++ b/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy @@ -1409,4 +1409,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": [ + "maxErrValSize": 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