common-workflow-language / common-workflow-language/cwltool
[Feature Request] Handling exception message in JavascriptExpression
- Dominant language
- Python
- Stars
- 376
- Forks
- 255
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 12
Description
I am not sure to send this request to this repository or `common-workflow-language/common-workflow-language`.
Finally I decided to send it here because this request can be done without changing the specification.
---
It would be nice if `cwltool` can treat a message from an exception thrown from a Javascript Expression as an error message for `permanentFailure` caused in the corresponding Javascript Expression.
It enables us to make more user-friendly error messages for the errors in Javascript Expressions.
## Input tool and parameters
Several tools such as `tophat2` and `bowtie2` support both of single end and pair end inputs.
The following is a CWL file to support both types of inputs.
- It has `read_layout` parameter that takes `single end` or `pair end`,
- It may take `fq` or `fq1` and `fq2` as input parameters according to the value of `read_layout`, and
- If `read_layout` is `single end` (or `pair end`), it rejects the inputs with `fq1` and `fq2` (or `fq`, respectively).
```cwl
# sample.cwl
cwlVersion: v1.0
class: CommandLineTool
requirements:
- class: InlineJavascriptRequirement
baseCommand: echo
inputs:
read_layout:
type:
type: enum
symbols:
- single end
- pair end
fastq:
type:
- type: record
label: single end
fields:
fq:
type: string
inputBinding:
valueFrom: |
${
if (inputs.read_layout != "single end") {
throw new Error('A parameter "fq" is valid if "read_layout" is "single end"')
}
return self
}
- type: record
label: pair end
fields:
fq1:
type: string
inputBinding:
valueFrom: |
${
if (inputs.read_layout != "pair end") {
throw new Error('A parameter "fq1" is valid if "read_layout" is "pair end"')
}
return self
}
fq2:
type: string
inputBinding: {}
outputs: {}
```
Here is a sample parameter file:
```yaml
# sample.yml
read_layout: pair end
fastq:
fq: fastq (single end) # It will be rejected because `read_layout` is `pair end` but this specifies `fq`
```
## Expected Behavior
```console
$ cwltool sample.cwl sample.yml
...
Error: A parameter "fq" is valid if "read_layout" is "single end" in sample.cwl:23:15
```
If `cwltool` treats a message from the exception as a message for `permanentFailure`, we can easily know what is the problem for the input parameters :-)
## Actual Behavior
```console
$ cwltool sample.cwl sample.yml
...
sample.cwl:23:15: Expression evaluation error:
Expecting value: line 1 column 1 (char 0)
script was:
01 "use strict";
02 var inputs = {
03 "read_layout": "pair end",
04 "fastq": {
05 "fq": "fastq (single end)"
06 }
07 };
08 var self = "fastq (single end)";
09 var runtime = {
10 "cores": 1,
11 "ram": 1024,
12 "tmpdirSize": 1024,
13 "outdirSize": 1024,
14 "tmpdir":
"/private/var/folders/gk/zyzswjbs6m59ywz69zhrtmlh0000gn/T/tmpfpc2xxzk",
15 "outdir": "/private/tmp/docker_tmpyu8mqyoq"
16 };
17 (function(){
18 if (inputs.read_layout != "single end") {
19 throw new Error('A parameter "fq" is valid if "read_layout" is "single
end"')
20 }
21 return self
22 })()
stdout was: ''
stderr was: 'evalmachine.:19
throw new Error('A parameter "fq" is valid if "read_layout" is "single end"')
^
Error: A parameter "fq" is valid if "read_layout" is "single end"
at evalmachine.:19:11
at evalmachine.:22:3
at Script.runInContext (vm.js:102:20)
at Script.runInNewContext (vm.js:108:17)
at Object.runInNewContext (vm.js:291:38)
at Socket. ([eval]:11:57)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:260:13)
at Socket.Readable.push (_stream_readable.js:219:10)'
```
This message is too long and hides the message `Error: A parameter "fq" is valid if "read_layout" is "single end"` that what I want to know.
Contributor guide
Assessment
This issue has not been assessed yet.