How to handle ".findAll.exists, found nothing"

To be fair Gatling is my first introduction to SCALA so the answer may be obvious to someone but I didn’t see it, and searching on the web did not get me anywhere fast

I was trying to get Gatling to parse the results of a JSON list that may be empty and process the list if it is not empty.

http(“get interesting stuff”)

This worked find and I could process the list if there were any documents attached to the object I was hitting but if the list is empty then I got the error:

jsonPath($.doclist[*].id).findAll.exists, found nothing

Eventually I realized I had to add the following after the .findAll and before the .saveAs:

.transformOption (extract => extract match {
case None => Some(Nil) // couldn’t extract anything, replacing with an empty list
case someNEL => someNEL

Enjoy or mock as you please.

Hi Anthony,

I think that what you may be looking for is ‘optional’ :

Using ‘optional’, your check will never fail but you’ll need to handle the fact that it may be missing by yourself (e.g. use the ‘.exists’ EL function to check that the value is indeed there).