# execute\_proces() interaction between COMMAND\_ERROR\_IS\_FATAL and TIMEOUT

**URL:** https://discourse.cmake.org/t/execute-proces-interaction-between-command-error-is-fatal-and-timeout/2303
**Category:** Development
**Created:** [December 6, 2020, 1:16am UTC](https://discourse.cmake.org/t/execute-proces-interaction-between-command-error-is-fatal-and-timeout/2303 "2020-12-06T01:16:30Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 6, 2020, 1:16am UTC](https://discourse.cmake.org/t/execute-proces-interaction-between-command-error-is-fatal-and-timeout/2303/1 "2020-12-06T01:16:30Z")

</div>

CMake 3.19 added a new `COMMAND_ERROR_IS_FATAL` option to the `execute_process()` command. The goal as originally stated in [the issue](https://gitlab.kitware.com/cmake/cmake/-/issues/19930) was to be able to replace code like this:

```cmake
execute_process(COMMAND foo RESULT_VARIABLE _result)
if(_result)
  message(FATAL_ERROR "foo returned ${_result}, should be 0")
endif()

```

With something more concise, which ended up being this:

```cmake
execute_process(COMMAND foo COMMAND_ERROR_IS_FATAL ANY)

```

This change was made in [MR 5243](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5243). In those discussions, we didn’t consider the effect of the `TIMEOUT` option. If the `TIMEOUT` option is used, we still have to provide a result variable and check it using the old method because it isn’t handled by `COMMAND_ERROR_IS_FATAL`. Should we consider this a bug in the implementation and fix it in 3.19.2, or is a timeout something we want to keep separate that `COMMAND_ERROR_IS_FATAL` should not catch?

Cc: @kyle.edwards

---

<div class="post-metadata">

### Author: ![asit-dhal](https://discourse.cmake.org/user_avatar/discourse.cmake.org/asit-dhal/32/996_2.png) [@asit-dhal](https://discourse.cmake.org/u/asit-dhal)
#### Post date: [December 6, 2020, 2:33am UTC](https://discourse.cmake.org/t/execute-proces-interaction-between-command-error-is-fatal-and-timeout/2303/2 "2020-12-06T02:33:28Z")

</div>

`COMMAND_ERROR_IS_FATAL` is an error condition. It explicitly checks the return code and prints the error message. `TIMEOUT` sets the `RESULT_VARIABLE`.  
If you want `COMMAND_ERROR_IS_FATAL` to catch timeout, how do you want this to be done?

If `COMMAND_ERROR_IS_FATAL` is not specified, `TIMEOUT` will set the `RESULT_VARIABLE`. Otherwise, it will fail with a message.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 6, 2020, 3:05am UTC](https://discourse.cmake.org/t/execute-proces-interaction-between-command-error-is-fatal-and-timeout/2303/3 "2020-12-06T03:05:07Z")

</div>

(I made a typo for the option name in my original post, which was repeated in your reply, I’ve corrected both to avoid future confusion)

> [@asit-dhal](#):
>
> Otherwise, it will fail with a message.

No it doesn’t fail, it silently continues. That’s what makes this particularly dangerous because failures due to a timeout go unnoticed. It did that before 3.19 already, but with the new `COMMAND_ERROR_IS_FATAL` option, one could assume that new option also catches timeouts. It would be understandable to go with the reasoning that the command is still failing, it’s taking longer than expected and timing out. That’s exactly what I did, I only found out it didn’t catch it because I was explicitly checking the behavior before updating some documentation around the new option.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [December 7, 2020, 2:34pm UTC](https://discourse.cmake.org/t/execute-proces-interaction-between-command-error-is-fatal-and-timeout/2303/4 "2020-12-07T14:34:07Z")

</div>

I think any time the `RESULT_VARIABLE` is not set to `0` is a candidate for capture with `COMMAND_ERROR_IS_FATAL`. Please look at adding this for 3.19.x.

---

<div class="post-metadata">

### Author: ![asit-dhal](https://discourse.cmake.org/user_avatar/discourse.cmake.org/asit-dhal/32/996_2.png) [@asit-dhal](https://discourse.cmake.org/u/asit-dhal)
#### Post date: [December 7, 2020, 4:54pm UTC](https://discourse.cmake.org/t/execute-proces-interaction-between-command-error-is-fatal-and-timeout/2303/5 "2020-12-07T16:54:51Z")

</div>

Someone create an issue, I will fix it as soon as possible.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [December 7, 2020, 4:57pm UTC](https://discourse.cmake.org/t/execute-proces-interaction-between-command-error-is-fatal-and-timeout/2303/6 "2020-12-07T16:57:15Z")

</div>

@asit-dhal thanks. I opened [CMake Issue 21562](https://gitlab.kitware.com/cmake/cmake/-/issues/21562) for this.
