@@ -207,13 +207,13 @@ together (they are dependent) or several arguments that cannot be provided
207207together (they are exclusive). You can use records and type unions to group
208208parameters together to describe these two conditions.
209209
210- ``` {literalinclude} /_includes/cwl/11-records /record.cwl
210+ ``` {literalinclude} /_includes/cwl/inputs /record.cwl
211211:language: cwl
212212:caption: "`record.cwl`"
213213:name: record.cwl
214214```
215215
216- ``` {literalinclude} /_includes/cwl/11-records /record-job1.yml
216+ ``` {literalinclude} /_includes/cwl/inputs /record-job1.yml
217217:language: yaml
218218:caption: "`record-job1.yml`"
219219:name: record-job1.yml
@@ -232,7 +232,7 @@ record-job1.yml:1:1: the `dependent_parameters` field is not valid because
232232
233233In the first example, you can't provide ` itemA ` without also providing ` itemB ` .
234234
235- ``` {literalinclude} /_includes/cwl/11-records /record-job2.yml
235+ ``` {literalinclude} /_includes/cwl/inputs /record-job2.yml
236236:language: yaml
237237:caption: "`record-job2.yml`"
238238:name: record-job2.yml
@@ -269,7 +269,7 @@ $ cat output.txt
269269In the second example, ` itemC ` and ` itemD ` are exclusive, so only ` itemC `
270270is added to the command line and ` itemD ` is ignored.
271271
272- ``` {literalinclude} /_includes/cwl/11-records /record-job3.yml
272+ ``` {literalinclude} /_includes/cwl/inputs /record-job3.yml
273273:language: yaml
274274:caption: "`record-job3.yml`"
275275:name: record-job3.yml
@@ -306,7 +306,67 @@ $ cat output.txt
306306In the third example, only ` itemD ` is provided, so it appears on the
307307command line.
308308
309- ``` {note} ```
309+ ### Exclusive Input Parameters with Expressions
310+
311+ If you use exclusive input parameters combined with expressions, you need to be
312+ aware that the ` inputs ` JavaScript object will contain one of the exclusive
313+ input values. This means that you might need to use an ** or** boolean operator
314+ to check which values are present.
315+
316+ Let's use an example that contains an exclusive ` output_format ` input parameter
317+ that accepts ` null ` (i.e. no value provided), or any value from an enum.
318+
319+ ``` {literalinclude} /_includes/cwl/inputs/exclusive-parameter-expressions.cwl
320+ :language: cwl
321+ :caption: "`exclusive-parameter-expressions.cwl`"
322+ :name: exclusive-parameter-expressions.cwl
323+ :emphasize-lines: 7, 21-23
324+ ```
325+
326+ Note how the JavaScript expression uses the value of the exclusive input parameter
327+ without taking into consideration a ` null ` value. If you provide a valid value,
328+ such as “fasta” (one of the values of the enum), your command should execute
329+ successfully:
330+
331+ ``` {code-block} console
332+ $ cwltool exclusive-parameter-expressions.cwl --output_format fasta
333+ INFO /home/kinow/Development/python/workspace/user_guide/venv/bin/cwltool 3.1.20220830195442
334+ INFO Resolved 'exclusive-parameter-expressions.cwl' to 'file:///tmp/exclusive-parameter-expressions.cwl'
335+ INFO [job exclusive-parameter-expressions.cwl] /tmp/j02lo8ky$ true \
336+ --format \
337+ fasta
338+ INFO [job exclusive-parameter-expressions.cwl] completed success
339+ {
340+ "text_output": "fasta"
341+ }
342+ INFO Final process status is success
343+ ```
344+
345+ However, if you do not provide any input value, then ` output_format ` will be
346+ evaluated to a ` null ` value, which does not match the expected type for the
347+ output field (a ` string ` ), resulting in failure when running your workflow.
348+
349+ ``` {code-block} console
350+ :emphasize-lines: 6-10
351+ $ cwltool exclusive-parameter-expressions.cwl
352+ INFO /home/kinow/Development/python/workspace/user_guide/venv/bin/cwltool 3.1.20220830195442
353+ INFO Resolved 'exclusive-parameter-expressions.cwl' to 'file:///tmp/exclusive-parameter-expressions.cwl'
354+ INFO [job exclusive-parameter-expressions.cwl] /tmp/jmq3nqap$ true
355+ ERROR [job exclusive-parameter-expressions.cwl] Job error:
356+ Error validating output record. the `text_output` field is not valid because
357+ the value is not string
358+ in {
359+ "text_output": null
360+ }
361+ WARNING [job exclusive-parameter-expressions.cwl] completed permanentFail
362+ {}
363+ WARNING Final process status is permanentFail
364+ ```
365+
366+ To correct it, you must remember to use an or operator in your JavaScript expression
367+ when using exclusive parameters, or any parameter that allows ` null ` . For example,
368+ the expression could be changed to ` $(inputs.output_format || 'auto') ` , to have
369+ a default value if none was provided in the command line or job input file.
310370
311371% TODO
312372%
0 commit comments