problem with recursive call

One of my test chains mimics a step to remove items from a cart.
I’ve implemented it recursively by going to the cart page and checking for a specific pattern until the cart page is empty.

I’ve implemented this like the following:

val chain: ChainBuilder = exec(http("Go To Cart Page")
.doIf(session => session("removeUrl").as[Option[String]].isDefined) {
exec(http("Removing entry")
.exec(ClearCart.chain) <---- hereNPE happens when running the test

When I run the test (actually the remove items is part of a wider test case) the simulation doesn’t even start and I get a NPE.
Any idea of what’s happening? Is this kind of “recursive chain” allowed?

Chains are built and materialized in the beginning, and then executed later. With a recursive chain, the attempt to build the chain will never complete. Turn it into a loop.