question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with + and optional variable

See original GitHub issue

Hello! I used this snippet of code successfully on the Cromwell with Google backend:

task fastqc {
  input {
    File f1
    File? f2
    Int? cpu=1
    Int? machine_mem_gb
    Int? preemptible_attempts
    String mode

    Float f2size = if (mode == "PE") then size(f2, "GB") else 0.0
    Int disk_space_gb = ceil(size(f1, "GB") + f2size) + 20
  }

  command {
      fastqc -t ~{cpu} --outdir $PWD ~{f1} ~{f2}
  }

  output {
      Array[File] html = glob("*html")
      Array[File] zip  = glob("*zip")
  }

  runtime {
    docker: "biocontainers/fastqc:v0.11.5_cv2"
    memory: select_first([machine_mem_gb, 4]) + " GB"
    cpu: cpu
    disks: "local-disk " + disk_space_gb + " HDD"
    preemptible: select_first([preemptible_attempts, 3])
  }
}

On local backend I got this error: _Failed to evaluate input '_disk_space_gb’ (reason 1 of 1): Sorry! Operation + is not supported on empty optional values. You might resolve this using select_first([optional, default]) to guarantee that you have a filled value.

I tried following the advice (even though I don’t see what is missing) Float f2size = select_first([if (mode == “PE”) then size(f2, “GB”) else 0.0]) And then I got an even more confusing error: Failed to process task definition ‘fastqc’ (reason 1 of 1): Failed to process expression ‘select_first([f2size, select_first([if (mode == “PE”) then size(f2, “GB”) else 0.0])])’ (reason 1 of 1): Invalid parameter ‘ArrayLiteral(Vector(TernaryIf(Equals(IdentifierLookup(mode),StringLiteral(PE)),Size(IdentifierLookup(f2),Some(StringLiteral(GB))),PrimitiveLiteralExpressionElement(WomFloat(0.0)))))’. Expected an array of optional values (eg ‘Array[X?]’) but got ‘Array[Float]+’

Can you help me understand? It all passes Womtools validation.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
OgnjenMiliceviccommented, Sep 16, 2020

OK, solved it. The whole block was in inputs which seem to be evaluated out of order or without it.

Moving the lines with basename out of the input block solved it!

Thanks!

0reactions
OgnjenMiliceviccommented, Sep 14, 2020

Actually, upon further examination b1 and b2 come up empty. Why does this triple basename return empty string? Is this not a valid synthax?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optionals : are bad practices still bad practices if everyone ...
A variable whose type is Optional should never itself be null ; it should always point to an Optional instance.
Read more >
Optionals cause more problems than they solve - Swift Forums
I understand the motivation to try and make it harder to for people to accidentally put in nil values but the priority of...
Read more >
Why isn't optional used for instance variables? - java
One reason not to use Optional for instance variables is that it's too easy for the Optional reference ...
Read more >
Named and Optional Arguments - C# Programming Guide
When you use named and optional arguments, the arguments are evaluated in the order in which they appear in the argument list, not...
Read more >
Should I raise an exception/error when an optional argument ...
An optional argument, almost by definition, is not an exceptional situation. It's probably not even an error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found