Skip to content

Invalid method invocation with arguments

Issue

You get an error such as:

ERROR ~ Invalid method invocation `call` with arguments: [i, am, a] (java.util.ArrayList) on _runScript_closure1 type  # (1)!

 -- Check '.nextflow-console.log' file for details
  1. Note that call can sometimes be reported as doCall.

Possible source

This normally means you are using a closure (e.g., within a map call) on a channel somewhere in your workflow in which you define variables for each element of the input channel.

You will get the error if the input channel has additional or fewer elements than defined in the closure function.

ch_input = Channel.of(['foo', 'bar', 'baz'])

ch_input.map{ one, two -> [one] }

or

ch_input = Channel.of(['foo'])

ch_input.map{ one, two -> [one] }

Solution

To fix, ensure that whenever you define variables to elements there is a one to one ratio of variable names to elements

ch_input = Channel.of(['foo', 'bar', 'baz'])

ch_input.map{ one, two, three -> [one] }

Note that the error message does not report where this happens, so you will have to look for all cases of a closure being applied to the channel with the channel contents as reported in the error, to find where this occurs (see the recommendation below for a way to get the exact line). Liberal use of the dump or view channel operator can help you spot a mismatch between expected and actual channel content.

Recommendation

Use static typing with Nextflow 26.10 or later. nextflow lint reports a closure whose number of parameters doesn't match the channel item, at the line where it happens (line numbers refer to the full script):

ch_input = channel.of(tuple('foo', 'bar', 'baz'))
ch_input.map { one, two -> one }
Error main.nf:5:18: Closure with signature (?, ?) -> ? is not compatible with expected signature: (E) -> R

Only tuples can be destructured in typed code, so create channel items with tuple(), or use records and access fields by name.