ExitBlockOnFail executes even when no errors are present

Heres a code snippet to show the layout of a ChainBuilder I created

.exec(
		http(Name)
				.post(url)
				.body(PebbleFileBody("pebbleTemplate.peb")).asJson() 
				.basicAuth(username, password)
				.check(status().is(200).saveAs("responseStatus"))
				.check(
						jmesPath("path")
								.ofMap()
								.find()
								.saveAs("appointment")
				)
				.check(bodyString().saveAs("responseBody"))
)
.exitBlockOnFail(
		exec(session -> {
			logger.error("Search Session failed for reason: {}", session.getString("responseStatus"));
			logger.error("Search Sessions response: \n {}", session.getString("responseBody"));
			return session;
		})
)

When something goes wrong I want to capture some additional data in a log file using log4j2.
I put this additional logic in an .exitBlockOnFail.

For some reason, the code in .exitBlockOnFail is executing even when my checks are passing; I can find the data I need and the request response is 200.
All other requests after this one pass with an OK status. Their exitBlockOnFail conditionals trigger as well.

The default logging that Gatling provides has been set to log if an error occurs in the requests. Its empty.

Why is the code inside .exitBlockOnFail executing? Does Gatling provide a way that I can get additional details on what caused a failure?

Hi @Drew!

I think you misunderstood the meaning of exitBlockOnFail.

Consider this ChainBuilder:

  exitBlockOnFail(
    exec(http("My Request that may fail").post(url)) // <1>
    .exec(http("Only if first request succeed").get(otherUrl)) // <2>
    .exec(http("Only if all previous succeed and so on").get(otherUrl)) // <3>
  )
  .exec(http("Always").get(otherUrl)) // <4>
  .doIf(Session::isFailed) // <5>
    .then(exec(session -> {
      logger.error("Search Session failed for reason: {}", session.getString("responseStatus"));
      logger.error("Search Sessions response: \n {}", session.getString("responseBody"));
      return session;
    }));

1, 2 and 3 are part of the exitBlockOnFail.
2 should be run only if 1 succeed
3 only if both previous succeed, etc.

Even in the case of one step failed in the exitBlockOnFail block. The steps outside (4) will run.

I think you want to log if the session is in failure state, as written in 5

Does that help?

Cheers!

You’re correct that I misunderstood. I thought it was treated as a sort of catch block; If the above block fails, execute this code. Instead exitBlockOnFail is quite literally saying exit this block immediately if any exec’s fail inside.