COMMAND_ERROR_IS_FATAL output isn't particularly helpful

Consider this script:

execute_process(
    COMMAND bash -c "exit 127"
    COMMAND_ERROR_IS_FATAL ANY
    )
message(STATUS "Got here")

This fails with:

$ cmake -P err.cmake
CMake Error at err.cmake:1 (execute_process):
  execute_process failed command indexes:

    1: "Child return code: 127"

Which is good - configuration does fail. However, the error isn’t very useful - it doesn’t actually say which command was running that failed, which can be very valuable in diagnosing the problem. It’d be great if COMMAND_ERROR_IS_FATAL caused cmake to log every (for ANY) or the one (for LAST) command that failed.

Compare that to this version:

function(execute_process2)
    cmake_parse_arguments(ARGS "" "COMMAND_ERROR_IS_FATAL" "COMMAND" ${ARGV})
    execute_process(
        COMMAND ${ARGS_COMMAND}
        RESULT_VARIABLE result)
    if(result)
        message(FATAL_ERROR "command ${ARGS_COMMAND} failed with error: ${result}")
    endif()
endfunction()

execute_process2(
    COMMAND bash -c "exit 127"
    COMMAND_ERROR_IS_FATAL ANY
    )
message(STATUS "Got here")

which fails with:

CMake Error at err.cmake:7 (message):
  command bash;-c;exit 127 failed with error: 127
Call Stack (most recent call first):
  err.cmake:11 (execute_process2)

This still isn’t great, since it prints bash;-c;exit 127 rather than bash -c "exit 127" and I have idea how to make that better, but at least I get an indication of what exactly failed.

1 Like

+1! I definitely agree that CMake’s output for failed execute_process calls needs to be better.

This seems worthy of a feature request to me.

1 Like