Throw exception on 0 documents

Hi All,

Apologies if this one has been asked before.

There is a scenario in the current pipeline being developed where after a filter operation the number of documents returned can be 0. at this point the pipeline completes as there is no further processing to be done.

I am looking for a pattern to capture this scenario so when there are 0 documents after this step in the process to throw an exception rather than fail silently.

has anyone come across this issue before?

Many thanks,
Kareem.

HI @ksalem,

You can build a mechanism that will check for existing documents, by using the Gate snap.

The Gate Snap will move the pipeline flow even if no documents are provided on the input. From there you can simply add a router that will check for documents (Ex. $input.lenght == 0) and throw an error by using the Exit snap.

Hope this helps,
Bojan

2 Likes

Thanks Bojan,

Thats exactly what I’m looking for!

Be careful with the Gate snap if the output of the filter could potentially be thousands of documents, or even hundreds of documents if they’re large documents. The Gate snap has a setting called Output Document Content which defaults to “All input documents”. That could result in a very memory-intensive output document. Since you’re only using this to test for no input, consider changing this setting to one of the other two options:

If there are no input documents, the output document will look like this:
image

2 Likes