cancel
Showing results for 
Search instead for 
Did you mean: 

Throw exception on 0 documents

ksalem
New Contributor II

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.

1 ACCEPTED SOLUTION

bojanvelevski
Valued Contributor

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

View solution in original post

3 REPLIES 3

bojanvelevski
Valued Contributor

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

ksalem
New Contributor II

Thanks Bojan,

Thats exactly what I’m looking for!

ptaylor
Employee
Employee

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:

image

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