sstrong99
(Steven Strong)
January 7, 2025, 8:35pm
1
I want to throw an error if a channel is not empty. I know i could pass the channel into a process that always errors, but i was hoping there was a little bit simpler of a method. For example, something similar to
Channel
.fromPath("xyz/*")
.ifEmpty {
log.error("ERROR...")
System.exit(2)
}
but with the inverse behavior
yinshiyi
(Shiyi Yin)
January 11, 2025, 12:30am
2
try this, it is not pretty, but works
The map part is needed otherwise the notEmpty error will execute with Empty channel input.
test_channel
.ifEmpty {
log.error("this is empty")
}
.first()
.map { it ->
if (it != null) {
log.error("this is not empty")
}
}
If a channel is empty, the following operator won’t do anything so simply add a map
on the end of your channel.
params.input = false
workflow {
ch_in = params.input ? Channel.fromList([1, 2, 3]) : Channel.empty()
ch_in.map{ error "Error: Channel is not empty" }
}
1 Like
sstrong99
(Steven Strong)
January 13, 2025, 9:06pm
4
thanks, that works great!