From ad5eda0b019624a1111c979d676c4814f9cc2120 Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Sat, 29 Jul 2023 17:59:10 +0200 Subject: [PATCH] Improve error message Signed-off-by: Paolo Di Tommaso --- .../nextflow/script/params/BaseParam.groovy | 22 +++++++++++++++++-- .../script/params/ParamsInTest.groovy | 5 +++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/modules/nextflow/src/main/groovy/nextflow/script/params/BaseParam.groovy b/modules/nextflow/src/main/groovy/nextflow/script/params/BaseParam.groovy index 21dba2f8bb..4a5165f8df 100644 --- a/modules/nextflow/src/main/groovy/nextflow/script/params/BaseParam.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/script/params/BaseParam.groovy @@ -18,7 +18,7 @@ package nextflow.script.params import groovy.util.logging.Slf4j import nextflow.exception.ScriptRuntimeException - +import nextflow.script.TokenVar /** * Base class for input/output parameters * @@ -146,7 +146,25 @@ abstract class BaseParam implements Cloneable { * Report missing method calls as possible syntax errors. */ def methodMissing( String name, def args ) { - throw new ScriptRuntimeException("Invalid method call `${name}(${args})` -- possible syntax error") + 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) + } } diff --git a/modules/nextflow/src/test/groovy/nextflow/script/params/ParamsInTest.groovy b/modules/nextflow/src/test/groovy/nextflow/script/params/ParamsInTest.groovy index a352990b22..60dba152bc 100644 --- a/modules/nextflow/src/test/groovy/nextflow/script/params/ParamsInTest.groovy +++ b/modules/nextflow/src/test/groovy/nextflow/script/params/ParamsInTest.groovy @@ -1001,10 +1001,11 @@ class ParamsInTest extends Dsl2Spec { } ''' when: - def process = parseAndReturnProcess(text) + parseAndReturnProcess(text) then: - thrown(ScriptRuntimeException) + def e = thrown(ScriptRuntimeException) + e.message == 'Invalid function call `val(y)` -- possible syntax error' } }