# Custom exit codes?

**URL:** <https://discourse.chef.io/t/custom-exit-codes/9543>\
**Category:** Chef Infra (archive)\
**Created:** [September 29, 2016, 9:18am UTC](https://discourse.chef.io/t/custom-exit-codes/9543 "2016-09-29T09:18:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgrint](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@mgrint](https://discourse.chef.io/u/mgrint)\
**Post date:** [September 29, 2016, 9:18am UTC](https://discourse.chef.io/t/custom-exit-codes/9543/1 "2016-09-29T09:18:40Z")

</div>

Hi all

Probably down to my lack of ruby, but how do/can I exit a recipe, with a custom error code?

I have a resource which may give an error code, and I want to exit depending on the value of it.

```
  if node.run_state['r_code'] == 600 
    exit(node.run_state['r_code'])
  end

```

It needs to be executed at the end of the recipe and I can’t put this in a ruby\_block, as I just get ChildConvergeError from the resource, and an exit code of 1.

Any help, will be greatly appreciated.

Thanks  
Mark

\*\* UPDATE \*\*

if i run the following with chef-zero, I get the error code.

```
r_code = 600
Chef::Application.fatal!("bailing out!!", 600) if r_code == 600

```

If I run on a configured client, I always get

`FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)`

I’ve tried adding `exit_status :disabled`` to client.rb, but cannot circumvent the ChildConverge Exception (and therefore exit code 1)

---

<div class="post-metadata">

**Author:** ![kallistec](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallistec/32/23_2.png) [@kallistec](https://discourse.chef.io/u/kallistec)\
**Post date:** [September 29, 2016, 6:26pm UTC](https://discourse.chef.io/t/custom-exit-codes/9543/2 "2016-09-29T18:26:24Z")

</div>

> [@mgrint](#):
>
> If I run on a configured client, I always get
> 
> FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Chef forks a second process to prevent any state created during the run from affecting future runs (also to make Chef's RAM use more predictable over time). Therefore nothing in your recipe code can change Chef's exit code because the parent process isn't running it.

You'll need to find another way to implement whatever it is you want to do.
