Skip to content

Commit

Permalink
Preserve error messages for user-friendliness
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Sherman <[email protected]>
  • Loading branch information
bentsherman committed Sep 18, 2023
1 parent 7f2fa29 commit 8a2db9a
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class NextflowDSLImpl implements ASTTransformation {
if( call.methodAsString=='include' && call.arguments instanceof ArgumentListExpression ) {
final allArgs = (ArgumentListExpression)call.arguments
if( allArgs.size() != 1 || allArgs[0] !instanceof ClosureExpression ) {
syntaxError(call, "Invalid include statement -- the correct syntax is `include { ... } from '...'`")
syntaxError(call, "Not a valid include statement -- the correct syntax is `include { ... } from '...'`")
return
}

Expand All @@ -230,13 +230,13 @@ class NextflowDSLImpl implements ASTTransformation {
}
// otherwise return an error
else {
syntaxError(call, "Invalid include module name")
syntaxError(call, "Not a valid include module name")
return
}
modulesList.addExpression(moduleX)
}
else {
syntaxError(call, "Invalid include module name")
syntaxError(call, "Not a valid include module name")
return
}
}
Expand Down Expand Up @@ -815,7 +815,7 @@ class NextflowDSLImpl implements ASTTransformation {
def nested = methodCall.objectExpression instanceof MethodCallExpression
log.trace "convert > input method: $methodName"

if( methodName in ['val','env','file','each','stdin','path','tuple'] ) {
if( methodName in ['val','env','file','each','set','stdin','path','tuple'] ) {
//this methods require a special prefix
if( !nested )
methodCall.setMethod( new ConstantExpression('_in_' + methodName) )
Expand Down Expand Up @@ -895,7 +895,7 @@ class NextflowDSLImpl implements ASTTransformation {
def nested = methodCall.objectExpression instanceof MethodCallExpression
log.trace "convert > output method: $methodName"

if( methodName in ['val','env','file','stdout','path','tuple'] && !nested ) {
if( methodName in ['val','env','file','set','stdout','path','tuple'] && !nested ) {
// prefix the method name with the string '_out_'
methodCall.setMethod( new ConstantExpression('_out_' + methodName) )
fixMethodCall(methodCall)
Expand Down Expand Up @@ -929,7 +929,7 @@ class NextflowDSLImpl implements ASTTransformation {
protected void fixMethodCall( MethodCallExpression methodCall ) {
final name = methodCall.methodAsString

withinTupleMethod = name == '_in_tuple' || name == '_out_tuple'
withinTupleMethod = name == '_in_set' || name == '_out_set' || name == '_in_tuple' || name == '_out_tuple'
withinEachMethod = name == '_in_each'

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ abstract class BaseScript extends Script implements ExecutionContext {
}

protected process( String name, Closure<BodyDef> body ) {
log.info "BaseScript.process ${name}"
def process = new ProcessDef(this,body,name)
meta.addDefinition(process)
}
Expand Down
11 changes: 11 additions & 0 deletions modules/nextflow/src/main/groovy/nextflow/script/IncludeDef.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ class IncludeDef {
@PackageScope Map addedParams
private Session session

@Deprecated
IncludeDef( String module ) {
throw new DeprecationException("Anonymous module inclusion is deprecated -- Replace `include '${module}'` with `include { MODULE_NAME } from '${module}'`")
}

@Deprecated
IncludeDef(TokenVar token, String alias=null) {
def component = token.name; if(alias) component += " as $alias"
throw new DeprecationException("Unwrapped module inclusion is deprecated -- Replace `include $component from './MODULE/PATH'` with `include { $component } from './MODULE/PATH'`")
}

protected IncludeDef(List<Module> modules) {
this.modules = new ArrayList<>(modules)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,22 @@ class ProcessConfig implements Map<String,Object>, Cloneable {
'afterScript',
'beforeScript',
'cache',
'cleanup',
'clusterOptions',
'conda',
'cpus',
'container',
'containerOptions',
'cpus',
'cleanup',
'clusterOptions',
'debug',
'disk',
'echo', // deprecated
'errorStrategy',
'executor',
'ext',
'fair',
'label',
'machineType',
'queue',
'label',
'maxErrors',
'maxForks',
'maxRetries',
Expand All @@ -71,24 +73,24 @@ class ProcessConfig implements Map<String,Object>, Cloneable {
'penv',
'pod',
'publishDir',
'queue',
'resourceLabels',
'scratch',
'secret',
'shell',
'spack',
'stageInMode',
'stageOutMode',
'storeDir',
'tag',
'time',
// input-output qualifiers
'file',
'set',
'val',
'each',
'env',
'secret',
'stdin',
'stdout'
'stdout',
'stageInMode',
'stageOutMode',
'resourceLabels'
]

/**
Expand Down Expand Up @@ -533,6 +535,10 @@ class ProcessConfig implements Map<String,Object>, Cloneable {
new EachInParam(this).bind(obj)
}

InParam _in_set( Object... obj ) {
throw new DeprecationException("Input of type `set` is deprecated -- Use `tuple` instead")
}

InParam _in_tuple( Object... obj ) {
new TupleInParam(this).bind(obj)
}
Expand Down Expand Up @@ -597,6 +603,10 @@ class ProcessConfig implements Map<String,Object>, Cloneable {
}
}

OutParam _out_set( Object... obj ) {
throw new DeprecationException("Output of type `set` is deprecated -- Use `tuple` instead")
}

OutParam _out_tuple( Object... obj ) {
new TupleOutParam(this) .bind(obj)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ abstract class BaseInParam extends BaseParam implements InParam {
throw new IllegalArgumentException(message)
}

BaseInParam from( def obj ) {
throw new ScriptRuntimeException("Process clause `from` is no longer supported in DSL2")
}

void setFrom( obj ) {
checkFromNotNull(obj)
fromObject = obj
Expand All @@ -169,6 +173,10 @@ abstract class BaseInParam extends BaseParam implements InParam {
throw new IllegalStateException("Missing input channel")
}

BaseInParam from( Object... obj ) {
throw new ScriptRuntimeException("Process clause `from` is no longer supported in DSL2")
}

def decodeInputs( List inputs ) {
final UNDEF = -1 as short
def value = inputs[index]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ abstract class BaseOutParam extends BaseParam implements OutParam {
return this
}

BaseOutParam into( def value ) {
throw new ScriptRuntimeException("Process clause `into` is no longer supported in DSL2")
}

BaseOutParam into( TokenVar... vars ) {
throw new ScriptRuntimeException("Process clause `into` is no longer supported in DSL2")
}

void setInto( Object obj ) {
intoObj = obj
}
Expand All @@ -159,6 +167,12 @@ abstract class BaseOutParam extends BaseParam implements OutParam {
return outChannels ? outChannels.get(0) : null
}

@Deprecated
List<DataflowWriteChannel> getOutChannels() {
init()
return outChannels
}

String getName() {
if( nameObj != null )
return nameObj.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ interface InParam extends Cloneable {

Object getRawChannel()

InParam from( Object value )

InParam from( Object... values )

short index

short mapIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ class ScriptIncludesTest extends Dsl2Spec {
def result = runner.setScript(SCRIPT).execute()
then:
def e = thrown(ScriptCompilationException)
e.message.contains "Invalid include statement -- the correct syntax is `include { ... } from '...'`"
e.message.contains "Not a valid include statement -- the correct syntax is `include { ... } from '...'`"

}

Expand Down

0 comments on commit 8a2db9a

Please sign in to comment.