Skip to content

Commit

Permalink
Also apply to toState
Browse files Browse the repository at this point in the history
  • Loading branch information
DriesSchaumont committed Jan 2, 2025
1 parent aabcaae commit 1aa3f74
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def _processToState(toState, key_, config_) {
assert toState.values().every{it instanceof CharSequence} : "Error in module '$key_': toState is a Map, but not all values are Strings"
assert toState.keySet().every{it instanceof CharSequence} : "Error in module '$key_': toState is a Map, but not all keys are Strings"
def toStateMap = toState.clone()
def allArgumentNames = config_.allArguments.collect{it.plainName}
def requiredOutputNames = config_.allArguments.findAll{it.required && it.direction == "Output"}.collect{it.plainName}
// turn the map into a closure to be used later on
toState = { it ->
Expand All @@ -173,6 +174,9 @@ def _processToState(toState, key_, config_) {
assert output instanceof Map : "Error in module '$key_': the output is not a Map"
assert state instanceof Map : "Error in module '$key_': the state is not a Map"
def extraEntries = toStateMap.collectMany{newkey, origkey ->
if (!allArgumentNames.contains(origkey)) {
throw new Exception("Error processing toState for '$key_': invalid argument '$origkey'")
}
// check whether newkey corresponds to a required argument
if (output.containsKey(origkey)) {
[[newkey, output[origkey]]]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: invalid_tostate_argument
namespace: test_wfs
resources:
- type: nextflow_script
path: main.nf
entrypoint: base
# TODO: make absolute when the ns build uses the right CWD
- path: ../../../resources
dependencies:
- name: sub_workflow
platforms:
- type: nextflow
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
workflow base {
take: input_ch
main:

// generate list from 0 to 1000
ch = Channel.fromList(0..1000)
| map { num ->
// create temporary file
def file = tempFile()
file.write("num: $num")

["num$num", [ file: file ], ["num": num]]
}
| sub_workflow.run(
fromState: [
"file": "file",
],
toState: [
"step1_output": "output",
"file": "file",
"newkey": "thisargumentdoesnotexist" // This should raise
]
)


emit:
input_ch
}
13 changes: 13 additions & 0 deletions src/test/scala/io/viash/runners/nextflow/NextflowScriptTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,19 @@ class NextflowScriptTest extends AnyFunSuite with BeforeAndAfterAll {
assert(stdOut.contains("Error processing fromState for 'sub_workflow': invalid argument 'thisargumentdoesnotexist'"))
}

test("Test invalid argument in toState map", DockerTest, NextflowTest) {
val (exitCode, stdOut, stdErr) = NextflowTestHelper.run(
mainScript = "target/nextflow/test_wfs/invalid_tostate_argument/main.nf",
args = List(
"--publish_dir", "output"
),
cwd = tempFolFile
)

assert(exitCode == 1, s"\nexit code was $exitCode\nStd output:\n$stdOut\nStd error:\n$stdErr")
assert(stdOut.contains("Error processing toState for 'sub_workflow': invalid argument 'thisargumentdoesnotexist'"))
}


test("Run multiple output channels standalone", NextflowTest) {
val (exitCode, stdOut, stdErr) = NextflowTestHelper.run(
Expand Down

0 comments on commit 1aa3f74

Please sign in to comment.