Skip to content

Commit

Permalink
Improve error message
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Jul 29, 2023
1 parent 2176060 commit ad5eda0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

}

0 comments on commit ad5eda0

Please sign in to comment.