Skip to content

Commit

Permalink
Add strict mode flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pditommaso committed Jun 29, 2020
1 parent 48cf002 commit 4ba5ac1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions modules/nextflow/src/main/groovy/nextflow/NF.groovy
Expand Up @@ -56,4 +56,8 @@ class NF {
return WorkflowBinding.lookup(value)
return session().getBinding().getVariableName(value)
}

static boolean isStrictMode() {
NextflowMeta.instance.isStrictModeEnabled()
}
}
7 changes: 7 additions & 0 deletions modules/nextflow/src/main/groovy/nextflow/NextflowMeta.groovy
Expand Up @@ -24,13 +24,16 @@ class NextflowMeta {
static class Preview {
volatile float dsl

boolean strict

void setDsl( float num ) {
if( num != 2 && num != 1 )
throw new IllegalArgumentException("Not a valid DSL version number: $num")
if( num == 2 && !ignoreWarnDsl2 )
log.warn1 "DSL 2 IS AN EXPERIMENTAL FEATURE UNDER DEVELOPMENT -- SYNTAX MAY CHANGE IN FUTURE RELEASE"
dsl = num
}

}

final VersionNumber version
Expand Down Expand Up @@ -81,4 +84,8 @@ class NextflowMeta {
void disableDsl2() {
preview.dsl = 1
}

boolean isStrictModeEnabled() {
preview.strict
}
}
Expand Up @@ -96,7 +96,6 @@ import nextflow.util.CollectionHelper
import nextflow.util.LockManager
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer

/**
* Implement nextflow process execution logic
*
Expand Down Expand Up @@ -336,6 +335,15 @@ class TaskProcessor {

int getMaxForks() { maxForks }

protected void checkWarn(String msg, Map opts) {
if( NF.isStrictMode() )
throw new ProcessUnrecoverableException(msg)
if( opts )
log.warn1(opts, msg)
else
log.warn(msg)
}

/**
* Launch the 'script' define by the code closure as a local bash script
*
Expand All @@ -361,12 +369,12 @@ class TaskProcessor {
// -- check that input set defines at least two elements
def invalidInputSet = config.getInputs().find { it instanceof TupleInParam && it.inner.size()<2 }
if( invalidInputSet )
log.warn "Input `set` must define at least two component -- Check process `$name`"
checkWarn "Input `set` must define at least two component -- Check process `$name`"

// -- check that output set defines at least two elements
def invalidOutputSet = config.getOutputs().find { it instanceof TupleOutParam && it.inner.size()<2 }
if( invalidOutputSet )
log.warn "Output `set` must define at least two component -- Check process `$name`"
checkWarn "Output `set` must define at least two component -- Check process `$name`"

/**
* Verify if this process run only one time
Expand Down Expand Up @@ -587,7 +595,8 @@ class TaskProcessor {
final actual = entry instanceof Collection ? entry.size() : (entry instanceof Map ? entry.size() : 1)

if( actual != expected ) {
log.warn1("Input tuple does not match input set cardinality declared by process `$name` -- offending value: $entry", firstOnly: true, cacheKey: this)
final msg = "Input tuple does not match input set cardinality declared by process `$name` -- offending value: $entry"
checkWarn(msg, [firstOnly: true, cacheKey: this])
}
}
}
Expand Down Expand Up @@ -776,7 +785,7 @@ class TaskProcessor {
return true
}
if( invalid ) {
log.warn "[$task.name] StoreDir can only be used when using 'file' outputs"
checkWarn "[$task.name] StoreDir can only be used when using 'file' outputs"
return false
}

Expand Down Expand Up @@ -858,7 +867,7 @@ class TaskProcessor {

}
catch( Throwable e ) {
log.warn1("[$task.name] Unable to resume cached task -- See log file for details", causedBy: e)
log.warn1("[$task.name] Unable to resume cached task -- See log file for details", )
return false
}

Expand Down

0 comments on commit 4ba5ac1

Please sign in to comment.