# Exit entire simulation on condition / error

**URL:** <https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318>\
**Category:** Gatling (Open-Source)\
**Created:** [November 19, 2021, 11:59am UTC](https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318 "2021-11-19T11:59:36Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robin\_Cox](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@Robin\_Cox](https://community.gatling.io/u/Robin_Cox)\
**Post date:** [November 19, 2021, 11:59am UTC](https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318/1 "2021-11-19T11:59:36Z")

</div>

Hello,

We’ve got a simulation comprised of multiple sequential scenarios. The first one will optionally perform some data setup and I’d like to be able to terminate the entire simulation based on certain conditions at the end of this first scenario. Exiting if this first scenario errors would also be acceptable.

At the moment if I cause that first scenario to fail and use something like `exitHereIfFailed` I see the error is produced, but the subsequent scenarios continue as normal. Is there a recommended way of performing this kind of setup?

Cheers

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [November 21, 2021, 2:00pm UTC](https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318/2 "2021-11-21T14:00:42Z")

</div>

Hi,

I couldn’t find a proper workaround so I added a new DSL component to be available in 3.7, see [https://github.com/gatling/gatling/issues/4162](https://github.com/gatling/gatling/issues/4162)

Regards

---

<div class="post-metadata">

**Author:** ![Robin\_Cox](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@Robin\_Cox](https://community.gatling.io/u/Robin_Cox)\
**Post date:** [November 22, 2021, 10:23am UTC](https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318/3 "2021-11-22T10:23:52Z")

</div>

Hi Stéphane,

Thanks for the quick solution, I’ll try building that locally to see how it works.

Do you have any idea on when 3.7 will be available?

Cheers

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [November 22, 2021, 10:28am UTC](https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318/4 "2021-11-22T10:28:56Z")

</div>

Gatling 3.7 will be out tomorrow.  
Gatling Enterprise and Cloud releases supporting Gatling 3.7 will follow in the next few days, probably on Wednesday and Thursday respectively.

---

<div class="post-metadata">

**Author:** ![Robin\_Cox](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@Robin\_Cox](https://community.gatling.io/u/Robin_Cox)\
**Post date:** [November 22, 2021, 11:53am UTC](https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318/5 "2021-11-22T11:53:10Z")

</div>

That’s great, thanks!

---

<div class="post-metadata">

**Author:** ![Robin\_Cox](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@Robin\_Cox](https://community.gatling.io/u/Robin_Cox)\
**Post date:** [November 24, 2021, 12:00pm UTC](https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318/6 "2021-11-24T12:00:35Z")

</div>

Hi Stéphane,

I’ve just tried this out this morning and I’m still having trouble. Perhaps the way we’re constructing the scenarios won’t work with this new method? Are we doing something wrong?

Here’s a gist where I’ve provided a skeleton of how the simulation fits together. The first two steps are where we perform checks that I’d like to use to exit the simulation completely if the checks don’t pass or if an error is produced.

[https://gist.github.com/RobinJDCox/f97d8071fe0452cb20adc131f46c0098](https://gist.github.com/RobinJDCox/f97d8071fe0452cb20adc131f46c0098)

Cheers

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [November 24, 2021, 12:41pm UTC](https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318/7 "2021-11-24T12:41:32Z")

</div>

Please provide a full working example.

---

<div class="post-metadata">

**Author:** ![Robin\_Cox](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@Robin\_Cox](https://community.gatling.io/u/Robin_Cox)\
**Post date:** [November 24, 2021, 2:00pm UTC](https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318/8 "2021-11-24T14:00:13Z")

</div>

Sure, here’s a complete example. I’m hoping to prevent the main scenario from running by making either of the previous two steps fail

[https://gist.github.com/RobinJDCox/b42adf57688357c4c99f7c255a84775b](https://gist.github.com/RobinJDCox/b42adf57688357c4c99f7c255a84775b)

Cheers

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [November 24, 2021, 2:04pm UTC](https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318/9 "2021-11-24T14:04:17Z")

</div>

.exitHereIfFailed  
.stopInjector(“Error during database population”)

With the exitHereIfFailed , you’re telling the user to exit its scenario so it never reaches stopInjector

---

<div class="post-metadata">

**Author:** ![Robin\_Cox](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@Robin\_Cox](https://community.gatling.io/u/Robin_Cox)\
**Post date:** [November 24, 2021, 2:16pm UTC](https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318/10 "2021-11-24T14:16:58Z")

</div>

Okay sure, that makes sense. I guess I’m not sure how best to use stop injector then?

If I build a scenario with the stop injector included then it will always stop the simulation. How can I only invoke stop in certain conditions (e.g. an error is raised)?

Thanks for your help

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [November 24, 2021, 2:29pm UTC](https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318/11 "2021-11-24T14:29:38Z")

</div>

In a doIf block? eg

doIf(\_.isFailed) {  
stopInjector(“whatever”)  
}

---

<div class="post-metadata">

**Author:** ![Robin\_Cox](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@Robin\_Cox](https://community.gatling.io/u/Robin_Cox)\
**Post date:** [November 24, 2021, 2:32pm UTC](https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318/12 "2021-11-24T14:32:33Z")

</div>

Oh of course, thanks Stéphane!

---

<div class="post-metadata">

**Author:** ![Robin\_Cox](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@Robin\_Cox](https://community.gatling.io/u/Robin_Cox)\
**Post date:** [November 25, 2021, 11:24am UTC](https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318/13 "2021-11-25T11:24:50Z")

</div>

Hi - this appears to be working great locally now. Thanks for all your help.

Do we need to upgrade anything else in order to use 3.7? We’re seeing this message when running from frontline

Failed to validate packages: Simulation was compiled with an incompatible Gatling version: 3.7.1. Please upgrade to 3.5. Terminating instances.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [November 25, 2021, 11:53am UTC](https://community.gatling.io/t/exit-entire-simulation-on-condition-error/6318/14 "2021-11-25T11:53:12Z")

</div>

We’re about to release Gatling Enterprise 1.16.0 that will support Gatling 3.7.  
You’ll have to upgrade.
