# Is there any way to instruct Gatling to stop a scenario after the first KO?

**URL:** <https://community.gatling.io/t/is-there-any-way-to-instruct-gatling-to-stop-a-scenario-after-the-first-ko/3345>\
**Category:** Gatling (Open-Source)\
**Created:** [October 27, 2016, 9:22am UTC](https://community.gatling.io/t/is-there-any-way-to-instruct-gatling-to-stop-a-scenario-after-the-first-ko/3345 "2016-10-27T09:22:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene\_Abramchuk](https://avatars.discourse-cdn.com/v4/letter/e/8c91f0/32.png) [@Eugene\_Abramchuk](https://community.gatling.io/u/Eugene_Abramchuk)\
**Post date:** [October 27, 2016, 9:22am UTC](https://community.gatling.io/t/is-there-any-way-to-instruct-gatling-to-stop-a-scenario-after-the-first-ko/3345/1 "2016-10-27T09:22:17Z")

</div>

Hi all,

I am trying to find an efficient way of stopping a scenario right after an error occurs since it makes no sense in littering the report with errors, which are only caused by a single failed step in the chain of calls.

My scenario looks like this (snippet):

> ```auto
> override def scenario =
> AccountCreate.create.exitHereIfFailed
> .exec(AccountLogin.login().pause(1 seconds).exitHereIfFailed
> .exec(AccountActivate.activate.exitHereIfFailed
> 
> ```

So far, I identified three possible options for the execution:

1. Execute the scenario, skip the erroneous step, move on with the next one (this is the **default** behaviour).  
\*\*\* Unfortunately, it litters the report with irrelevant errors and makes it harder to debug and analyse.  
For example, failing to log in to an app will cause a cascade of unauthorized errors to pour in.  
I read Stephane’s reasoning that in a real-world scenario a user is likely to retry to log in, however I find it easier to control the load on the server just by spawning one more user anew.

2. Execute the scenario with each call completed with the exitHereIfFailed statement (shown above):  
\*\*\* Does the job well and as expected, however it is incredibly cluttered (imagine you have N calls, they you also need to add N exitHere… statements).

3. Execute the scenario within the exitBlockIfFails wrapper:  
\*\*\* Clean approach, but does not work with the ScenarioBuilder.  
The biggest gripe with it is actually that **the failed scenario step is not included to the output/report**.  
And that **the simulation is marked as success and has exit code 0**. (looks rather like a defect to me)

I am new to Scala and Gatling, perhaps, I misunderstand the approaches? I appreciate any comments.

---

<div class="post-metadata">

**Author:** ![Eugene\_Abramchuk](https://avatars.discourse-cdn.com/v4/letter/e/8c91f0/32.png) [@Eugene\_Abramchuk](https://community.gatling.io/u/Eugene_Abramchuk)\
**Post date:** [November 2, 2016, 8:54am UTC](https://community.gatling.io/t/is-there-any-way-to-instruct-gatling-to-stop-a-scenario-after-the-first-ko/3345/2 "2016-11-02T08:54:09Z")

</div>

Anyone, please?

---

<div class="post-metadata">

**Author:** ![sunbeltdn](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@sunbeltdn](https://community.gatling.io/u/sunbeltdn)\
**Post date:** [November 4, 2016, 8:53am UTC](https://community.gatling.io/t/is-there-any-way-to-instruct-gatling-to-stop-a-scenario-after-the-first-ko/3345/3 "2016-11-04T08:53:29Z")

</div>

I once used tryMax{}.exitHereIfFailed, it will retry once KO ocurrs then exit when all retry time as defined, it will skip the following test cases.

在 2016年10月27日星期四 UTC-7上午2:22:18，Eugene Abramchuk写道：

---

<div class="post-metadata">

**Author:** ![Eugene\_Abramchuk](https://avatars.discourse-cdn.com/v4/letter/e/8c91f0/32.png) [@Eugene\_Abramchuk](https://community.gatling.io/u/Eugene_Abramchuk)\
**Post date:** [November 9, 2016, 5:14pm UTC](https://community.gatling.io/t/is-there-any-way-to-instruct-gatling-to-stop-a-scenario-after-the-first-ko/3345/4 "2016-11-09T17:14:41Z")

</div>

Solved (kind of) by moving .exitHereIfFailed to all the actions inside.
