if (defined(x)) and optionals

pshapiropshapiro Member, Broadie
edited January 26 in Ask the WDL team

We're updating to Cromwell 30 and are seeing some changes where 30 is stricter than 29 on what it will allow. One case we've seen is where we have a task that executes inside a conditional block, such as

if (defined(x)) {
  call Task { input: x = x }

Now Cromwell requires that x is declared as optional in our task Task. Is there a form where we can enforce that an object is defined and bind a new object to the non-optional type? We'd rather not propagate optionals throughout our workflow, especially in cases where we know the inputs are always defined. We've come up with workarounds like:

if (defined(x)) {
  call Task { input: x = ${default="can never happen!" x}}

but this seems like a hack.


  • ChrisLChrisL Cambridge, MAMember, Broadie, Moderator, Dev
    edited January 29
    1. I'm not sure what that example's syntax is but AFAIK ${} only works inside string literals or in command blocks. I'm surprised (and mildly concerned) if it works in input blocks!
    2. The "expression" way of doing that is select_first. If you know it's good you can say select_first([x]) to get an X instead of an X?.
    3. Gazing into the future, you might like to check out and comment on https://github.com/openwdl/wdl/issues/187. This is to add an equivalent to the scatter block for optionals instead of arrays.
Sign In or Register to comment.