extend::on_error callback is not invoked if exception-based error reporting is used
- Dominant language
- C++
- Stars
- 145
- Forks
- 151
- PR merge metrics
- No merged PRs in 30d
Description
[extend::on_error](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/process/extend/on_error.html) is not invoked when `exec()` (POSIX) or `CreateProcess()` (Windows) fails.
This is because `set_error()` called after `exec()` ([[1]](https://github.com/boostorg/process/blob/develop/include/boost/process/detail/posix/executor.hpp#L433), [[2]](https://github.com/boostorg/process/blob/develop/include/boost/process/detail/posix/executor.hpp#L265)) / `CreateProcess()` ([[1]](https://github.com/boostorg/process/blob/develop/include/boost/process/detail/windows/executor.hpp#L210)) failure throws an exception and therefore subsequent code block is not executed, causing `on_error` handler to be omitted.
A minimal reproducer:
```
#include
#include
#include
#include
namespace bp = boost::process;
TEST(BoostProcessTest, on_error) {
{
bool called{false};
std::error_code ec;
bp::child{bp::exe = "some_nonexistent_path", ec, bp::extend::on_error = [&](auto, auto) { called = true; }}.wait();
EXPECT_TRUE(called);
}
{
bool called{false};
try {
bp::child{bp::exe = "some_nonexistent_path", bp::extend::on_error = [&](auto, auto) { called = true; }}.wait();
} catch (...) {
}
// EXPECT_TRUE(called);
EXPECT_FALSE(called); // Boost.Process bug
}
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.