Skip to content

Commit 80a4a9a

Browse files
authored
Merge pull request #114 from nextflow-io/add/debug-messages
Better error handling in configs
2 parents 6bbe910 + 26c1784 commit 80a4a9a

File tree

6 files changed

+266
-61
lines changed

6 files changed

+266
-61
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
1. Slow uniqueness check (> 2hrs for 100k samples) made 400x faster by switching from `findAll` to a `subMap` for isolating the required unique fields.
2020
2. `patternProperties` now has greater support, with no warnings about invalid parameters which actually match a pattern
21+
3. Added better error handling and debug messages to the configuration parser.
2122

2223
## Changes
2324

plugins/nf-schema/src/main/nextflow/validation/config/HelpConfig.groovy

Lines changed: 104 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,112 @@ import static nextflow.validation.utils.Colors.removeColors
1212

1313
@Slf4j
1414
class HelpConfig {
15-
final public Boolean enabled
16-
final public String shortParameter
17-
final public String fullParameter
18-
final public String showHiddenParameter
19-
final public String beforeText
20-
final public String afterText
21-
final public String command
22-
final public Boolean showHidden
15+
final public Boolean enabled = false
16+
final public Boolean showHidden = false
17+
18+
final public String showHiddenParameter = "showHidden"
19+
final public String shortParameter = "help"
20+
final public String fullParameter = "helpFull"
21+
final public String beforeText = ""
22+
final public String afterText = ""
23+
final public String command = ""
2324

2425
HelpConfig(Map map, Map params, Boolean monochromeLogs, Boolean showHiddenParams) {
2526
def config = map ?: Collections.emptyMap()
26-
enabled = config.enabled ?: false
27-
shortParameter = config.shortParameter ?: "help"
28-
fullParameter = config.fullParameter ?: "helpFull"
29-
showHiddenParameter = config.showHiddenParameter ?: "showHidden"
30-
if (monochromeLogs) {
31-
beforeText = config.beforeText ? removeColors(config.beforeText): ""
32-
afterText = config.afterText ? removeColors(config.afterText) : ""
33-
command = config.command ? removeColors(config.command) : ""
34-
} else {
35-
beforeText = config.beforeText ?: ""
36-
afterText = config.afterText ?: ""
37-
command = config.command ?: ""
38-
}
39-
showHidden = params.containsKey(showHiddenParameter) ? params.get(showHiddenParameter) : config.showHidden ?: showHiddenParams ?: false
27+
28+
// enabled
29+
if(config.containsKey("enabled")) {
30+
if(config.enabled instanceof Boolean) {
31+
enabled = config.enabled
32+
log.debug("Set `validation.help.enabled` to ${enabled}")
33+
} else {
34+
log.warn("Incorrect value detected for `validation.help.enabled`, a boolean is expected. Defaulting to `${enabled}`")
35+
}
36+
}
37+
38+
// showHiddenParameter
39+
if(config.containsKey("showHiddenParameter")) {
40+
if(config.showHiddenParameter instanceof String) {
41+
showHiddenParameter = config.showHiddenParameter
42+
log.debug("Set `validation.help.showHiddenParameter` to ${showHiddenParameter}")
43+
} else {
44+
log.warn("Incorrect value detected for `validation.help.showHiddenParameter`, a string is expected. Defaulting to `${showHiddenParameter}`")
45+
}
46+
}
47+
48+
// showHidden
49+
if(params.containsKey(showHiddenParameter) || config.containsKey("showHidden")) {
50+
if(params.get(showHiddenParameter) instanceof Boolean) {
51+
showHidden = params.get(showHiddenParameter)
52+
log.debug("Set `validation.help.showHidden` to ${showHidden} (Due to --${showHiddenParameter})")
53+
} else if(config.showHidden instanceof Boolean) {
54+
showHidden = config.showHidden
55+
log.debug("Set `validation.help.showHidden` to ${showHidden}")
56+
} else {
57+
log.warn("Incorrect value detected for `validation.help.showHidden` or `--${showHiddenParameter}`, a boolean is expected. Defaulting to `${showHidden}`")
58+
}
59+
}
60+
61+
// shortParameter
62+
if(config.containsKey("shortParameter")) {
63+
if(config.shortParameter instanceof String) {
64+
shortParameter = config.shortParameter
65+
log.debug("Set `validation.help.shortParameter` to ${shortParameter}")
66+
} else {
67+
log.warn("Incorrect value detected for `validation.help.shortParameter`, a string is expected. Defaulting to `${shortParameter}`")
68+
}
69+
}
70+
71+
// fullParameter
72+
if(config.containsKey("fullParameter")) {
73+
if(config.fullParameter instanceof String) {
74+
fullParameter = config.fullParameter
75+
log.debug("Set `validation.help.fullParameter` to ${fullParameter}")
76+
} else {
77+
log.warn("Incorrect value detected for `validation.help.fullParameter`, a string is expected. Defaulting to `${fullParameter}`")
78+
}
79+
}
80+
81+
// beforeText
82+
if(config.containsKey("beforeText")) {
83+
if(config.beforeText instanceof String) {
84+
if(monochromeLogs) {
85+
beforeText = config.beforeText
86+
} else {
87+
beforeText = removeColors(config.beforeText)
88+
}
89+
log.debug("Set `validation.help.beforeText` to ${beforeText}")
90+
} else {
91+
log.warn("Incorrect value detected for `validation.help.beforeText`, a string is expected. Defaulting to `${beforeText}`")
92+
}
93+
}
94+
95+
// afterText
96+
if(config.containsKey("afterText")) {
97+
if(config.afterText instanceof String) {
98+
if(monochromeLogs) {
99+
afterText = config.afterText
100+
} else {
101+
afterText = removeColors(config.afterText)
102+
}
103+
log.debug("Set `validation.help.afterText` to ${afterText}")
104+
} else {
105+
log.warn("Incorrect value detected for `validation.help.afterText`, a string is expected. Defaulting to `${afterText}`")
106+
}
107+
}
108+
109+
// command
110+
if(config.containsKey("command")) {
111+
if(config.command instanceof String) {
112+
if(monochromeLogs) {
113+
command = config.command
114+
} else {
115+
command = removeColors(config.command)
116+
}
117+
log.debug("Set `validation.help.command` to ${command}")
118+
} else {
119+
log.warn("Incorrect value detected for `validation.help.command`, a string is expected. Defaulting to `${command}`")
120+
}
121+
}
40122
}
41123
}

plugins/nf-schema/src/main/nextflow/validation/config/SummaryConfig.groovy

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package nextflow.validation.config
22

33
import groovy.util.logging.Slf4j
44

5+
import static nextflow.validation.utils.Colors.removeColors
6+
57
/**
68
* This class allows to model a specific configuration, extracting values from a map and converting
79
*
@@ -11,19 +13,50 @@ import groovy.util.logging.Slf4j
1113

1214
@Slf4j
1315
class SummaryConfig {
14-
final public String beforeText
15-
final public String afterText
16-
final public List<String> hideParams
16+
final public String beforeText = ""
17+
final public String afterText = ""
18+
19+
final public Set<String> hideParams = []
1720

1821
SummaryConfig(Map map, Boolean monochromeLogs) {
1922
def config = map ?: Collections.emptyMap()
20-
if (monochromeLogs) {
21-
beforeText = config.beforeText ? Utils.removeColors(config.beforeText): ""
22-
afterText = config.afterText ? Utils.removeColors(config.afterText) : ""
23-
} else {
24-
beforeText = config.beforeText ?: ""
25-
afterText = config.afterText ?: ""
23+
24+
// beforeText
25+
if(config.containsKey("beforeText")) {
26+
if(config.beforeText instanceof String) {
27+
if(monochromeLogs) {
28+
beforeText = config.beforeText
29+
} else {
30+
beforeText = removeColors(config.beforeText)
31+
}
32+
log.debug("Set `validation.summary.beforeText` to ${beforeText}")
33+
} else {
34+
log.warn("Incorrect value detected for `validation.summary.beforeText`, a string is expected. Defaulting to `${beforeText}`")
35+
}
36+
}
37+
38+
// afterText
39+
if(config.containsKey("afterText")) {
40+
if(config.afterText instanceof String) {
41+
if(monochromeLogs) {
42+
afterText = config.afterText
43+
} else {
44+
afterText = removeColors(config.afterText)
45+
}
46+
log.debug("Set `validation.summary.afterText` to ${afterText}")
47+
} else {
48+
log.warn("Incorrect value detected for `validation.summary.afterText`, a string is expected. Defaulting to `${afterText}`")
49+
}
50+
}
51+
52+
// hideParams
53+
if(config.containsKey("hideParams")) {
54+
if(config.hideParams instanceof List<String>) {
55+
hideParams = config.hideParams
56+
log.debug("Set `validation.summary.hideParams` to ${hideParams}")
57+
} else {
58+
log.warn("Incorrect value detected for `validation.summary.hideParams`, a list of strings is expected. Defaulting to `${hideParams}`")
59+
}
2660
}
27-
this.hideParams = config.hideParams ?: []
2861
}
2962
}

plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy

Lines changed: 116 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,136 @@ import nextflow.validation.exceptions.SchemaValidationException
1414
@Slf4j
1515
class ValidationConfig {
1616

17-
final public Boolean lenientMode
18-
final public Boolean monochromeLogs
19-
final public Boolean failUnrecognisedParams
20-
final public Boolean failUnrecognisedHeaders
21-
final public String parametersSchema
22-
final public Boolean showHiddenParams
17+
final public Boolean lenientMode = false
18+
final public Boolean monochromeLogs = false
19+
final public Boolean failUnrecognisedParams = false
20+
final public Boolean failUnrecognisedHeaders = false
21+
final public Boolean showHiddenParams = false
22+
2323
final public Integer maxErrValSize = 150
24+
25+
final public String parametersSchema = "nextflow_schema.json"
26+
27+
final public Set<String> ignoreParams = ["nf_test_output"] // Always ignore the `--nf_test_output` parameter to avoid warnings when running with nf-test
28+
2429
final public HelpConfig help
25-
final public SummaryConfig summary
2630

27-
final public List<String> ignoreParams
31+
final public SummaryConfig summary
2832

2933
ValidationConfig(Map map, Map params){
3034
def config = map ?: Collections.emptyMap()
31-
lenientMode = config.lenientMode ?: false
32-
monochromeLogs = config.monochromeLogs ?: false
33-
failUnrecognisedParams = config.failUnrecognisedParams ?: false
34-
failUnrecognisedHeaders = config.failUnrecognisedHeaders ?: false
35-
showHiddenParams = config.showHiddenParams ?: false
36-
if(config.maxErrValSize != null) {
37-
if(config.maxErrValSize >= 1 || config.maxErrValSize == -1) {
38-
maxErrValSize = config.maxErrValSize
35+
36+
// lenientMode
37+
if(config.containsKey("lenientMode")) {
38+
if(config.lenientMode instanceof Boolean) {
39+
lenientMode = config.lenientMode
40+
log.debug("Set `validation.lenientMode` to ${lenientMode}")
41+
} else {
42+
log.warn("Incorrect value detected for `validation.lenientMode`, a boolean is expected. Defaulting to `${lenientMode}`")
43+
}
44+
}
45+
46+
// monochromeLogs
47+
if(config.containsKey("monochromeLogs")) {
48+
if(config.monochromeLogs instanceof Boolean) {
49+
monochromeLogs = config.monochromeLogs
50+
log.debug("Set `validation.monochromeLogs` to ${monochromeLogs}")
3951
} else {
40-
log.warn("`validation.maxErrValSize` needs to be a value above 0 or equal to -1, defaulting to ${maxErrValSize}")
52+
log.warn("Incorrect value detected for `validation.monochromeLogs`, a boolean is expected. Defaulting to `${monochromeLogs}`")
4153
}
4254
}
55+
56+
// failUnrecognisedParams
57+
if(config.containsKey("failUnrecognisedParams")) {
58+
if(config.failUnrecognisedParams instanceof Boolean) {
59+
failUnrecognisedParams = config.failUnrecognisedParams
60+
log.debug("Set `validation.failUnrecognisedParams` to ${failUnrecognisedParams}")
61+
} else {
62+
log.warn("Incorrect value detected for `validation.failUnrecognisedParams`, a boolean is expected. Defaulting to `${failUnrecognisedParams}`")
63+
}
64+
}
65+
66+
// failUnrecognisedHeaders
67+
if(config.containsKey("failUnrecognisedHeaders")) {
68+
if(config.failUnrecognisedHeaders instanceof Boolean) {
69+
failUnrecognisedHeaders = config.failUnrecognisedHeaders
70+
log.debug("Set `validation.failUnrecognisedHeaders` to ${failUnrecognisedHeaders}")
71+
} else {
72+
log.warn("Incorrect value detected for `validation.failUnrecognisedHeaders`, a boolean is expected. Defaulting to `${failUnrecognisedHeaders}`")
73+
}
74+
}
75+
76+
// showHiddenParams
4377
if(config.containsKey("showHiddenParams")) {
4478
log.warn("configuration option `validation.showHiddenParams` is deprecated, please use `validation.help.showHidden` or the `--showHidden` parameter instead")
79+
if(config.showHiddenParams instanceof Boolean) {
80+
showHiddenParams = config.showHiddenParams
81+
log.debug("Set `validation.showHiddenParams` to ${showHiddenParams}")
82+
} else {
83+
log.warn("Incorrect value detected for `validation.showHiddenParams`, a boolean is expected. Defaulting to `${showHiddenParams}`")
84+
}
4585
}
46-
parametersSchema = config.parametersSchema ?: "nextflow_schema.json"
47-
help = new HelpConfig(config.help as Map ?: [:], params, monochromeLogs, showHiddenParams)
48-
summary = new SummaryConfig(config.summary as Map ?: [:], monochromeLogs)
4986

50-
if(config.ignoreParams && !(config.ignoreParams instanceof List<String>)) {
51-
throw new SchemaValidationException("Config value 'validation.ignoreParams' should be a list of String values")
87+
// maxErrValSize
88+
if(config.containsKey("maxErrValSize")) {
89+
if(config.maxErrValSize instanceof Integer && (config.maxErrValSize >= 1 || config.maxErrValSize == -1)) {
90+
maxErrValSize = config.maxErrValSize
91+
log.debug("Set `validation.maxErrValSize` to ${maxErrValSize}")
92+
} else {
93+
log.warn("`validation.maxErrValSize` needs to be a value above 0 or equal to -1. Defaulting to ${maxErrValSize}")
94+
}
95+
}
96+
97+
// parameterSchema
98+
if(config.containsKey("parametersSchema")) {
99+
if(config.parametersSchema instanceof String) {
100+
parametersSchema = config.parametersSchema
101+
log.debug("Set `validation.parametersSchema` to ${parametersSchema}")
102+
} else {
103+
log.warn("Incorrect value detected for `validation.parametersSchema`, a string is expected. Defaulting to `${parametersSchema}`")
104+
}
105+
}
106+
107+
// ignoreParams
108+
if(config.containsKey("ignoreParams")) {
109+
if(config.ignoreParams instanceof List<String>) {
110+
ignoreParams += config.ignoreParams
111+
log.debug("Added the following parameters to the ignored parameters: ${config.ignoreParams}")
112+
} else {
113+
log.warn("Incorrect value detected for `validation.ignoreParams`, a list with string values is expected. Defaulting to `${ignoreParams}`")
114+
}
52115
}
53-
ignoreParams = config.ignoreParams ?: []
54-
if(config.defaultIgnoreParams && !(config.defaultIgnoreParams instanceof List<String>)) {
55-
throw new SchemaValidationException("Config value 'validation.defaultIgnoreParams' should be a list of String values")
116+
117+
// defaultIgnoreParams
118+
if(config.containsKey("defaultIgnoreParams")) {
119+
if(config.defaultIgnoreParams instanceof List<String>) {
120+
ignoreParams += config.defaultIgnoreParams
121+
log.debug("Added the following parameters to the ignored parameters: ${config.defaultIgnoreParams}")
122+
} else {
123+
log.warn("Incorrect value detected for `validation.defaultIgnoreParams`, a list with string values is expected. Defaulting to `${ignoreParams}`")
124+
}
125+
}
126+
127+
// help
128+
def Map helpConfig = [:]
129+
if(config.containsKey("help")) {
130+
if(config.help instanceof Map) {
131+
helpConfig = config.help
132+
} else {
133+
log.warn("Incorrect value detected for `validation.help`, a map with key-value pairs is expected. Setting the defaults for all help options.")
134+
}
135+
}
136+
help = new HelpConfig(helpConfig, params, monochromeLogs, showHiddenParams)
137+
138+
// summary
139+
def Map summaryConfig = [:]
140+
if(config.containsKey("summary")) {
141+
if(config.summary instanceof Map) {
142+
summaryConfig = config.summary
143+
} else {
144+
log.warn("Incorrect value detected for `validation.summary`, a map with key-value pairs is expected. Setting the defaults for all summary options.")
145+
}
56146
}
57-
ignoreParams += config.defaultIgnoreParams ?: []
58-
ignoreParams += 'nf_test_output' //ignore `nf_test_output` directory when using nf-test
147+
summary = new SummaryConfig(summaryConfig, monochromeLogs)
59148
}
60149
}

plugins/nf-schema/src/test/nextflow/validation/ParamsHelpTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class ParamsHelpTest extends Dsl2Spec{
9898

9999
then:
100100
noExceptionThrown()
101-
stdout.size() == 10
101+
stdout.size() == 11
102102
}
103103

104104
def 'should print a help message with argument options' () {

plugins/nf-schema/src/test/nextflow/validation/ParamsSummaryLogTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class ParamsSummaryLogTest extends Dsl2Spec{
190190

191191
then:
192192
noExceptionThrown()
193-
stdout.size() == 13
193+
stdout.size() == 14
194194
stdout ==~ /.*\[0;34moutdir : .\[0;32moutDir.*/
195195
}
196196

0 commit comments

Comments
 (0)