Skip to content

Commit

Permalink
Fix incorrect error message on missing comma (#4085) [ci fast]
Browse files Browse the repository at this point in the history

Signed-off-by: Ben Sherman <[email protected]>
Signed-off-by: Paolo Di Tommaso <[email protected]>
Co-authored-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
bentsherman and pditommaso authored Jul 29, 2023
1 parent 51f5c84 commit a59af39
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
package nextflow.script.params

import groovy.util.logging.Slf4j

import nextflow.exception.ScriptRuntimeException
import nextflow.script.TokenVar
/**
* Base class for input/output parameters
*
Expand Down Expand Up @@ -141,4 +142,29 @@ abstract class BaseParam implements Cloneable {
return mapIndex >= 0
}

/**
* Report missing method calls as possible syntax errors.
*/
def methodMissing( String name, def args ) {
throw new ScriptRuntimeException("Invalid function call `${name}(${argsToString0(args)})` -- possible syntax error")
}

private String argsToString0(args) {
if( args instanceof Object[] )
args = Arrays.asList(args)
if( args instanceof List ) {
final result = new ArrayList()
for( def it : args )
result.add(argsToString1(it))
return result.join(',')
}
return argsToString1(args)
}

private String argsToString1(arg) {
if( arg instanceof TokenVar )
return arg.name
else
return String.valueOf((Object)arg)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import java.nio.file.Paths
import groovyx.gpars.dataflow.DataflowQueue
import groovyx.gpars.dataflow.DataflowVariable
import nextflow.Channel
import nextflow.exception.ScriptRuntimeException
import nextflow.processor.TaskProcessor
import spock.lang.Timeout
import test.Dsl2Spec
Expand Down Expand Up @@ -985,4 +986,26 @@ class ParamsInTest extends Dsl2Spec {
(in1.inner[1] as FileInParam).isNestedParam()
}

def 'should throw error on missing comma' () {
setup:
def text = '''
process hola {
input:
tuple val(x) val(y)
/command/
}
workflow {
hola(['x', 'y'])
}
'''
when:
parseAndReturnProcess(text)

then:
def e = thrown(ScriptRuntimeException)
e.message == 'Invalid function call `val(y)` -- possible syntax error'
}

}

0 comments on commit a59af39

Please sign in to comment.