Commit 277584d4 authored by Dominik Charousset's avatar Dominik Charousset

Deliver errors if requests fail with exceptions

(cherry picked from commit 7b5919d7)
parent 0565fe47
......@@ -791,6 +791,14 @@ auto scheduled_actor::activate(execution_unit* ctx, mailbox_element& x)
auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result {
CAF_LOG_TRACE(CAF_ARG(x));
#ifndef CAF_NO_EXCEPTIONS
auto handle_exception = [&](std::exception_ptr eptr) {
auto err = call_handler(exception_handler_, this, eptr);
if (x.mid.is_request()) {
auto rp = make_response_promise();
rp.deliver(err);
}
quit(std::move(err));
};
try {
#endif // CAF_NO_EXCEPTIONS
switch (consume(x)) {
......@@ -810,12 +818,10 @@ auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result {
} catch (std::exception& e) {
CAF_LOG_INFO("actor died because of an exception, what: " << e.what());
static_cast<void>(e); // keep compiler happy when not logging
auto eptr = std::current_exception();
quit(call_handler(exception_handler_, this, eptr));
handle_exception(std::current_exception());
} catch (...) {
CAF_LOG_INFO("actor died because of an unknown exception");
auto eptr = std::current_exception();
quit(call_handler(exception_handler_, this, eptr));
handle_exception(std::current_exception());
}
finalize();
return activation_result::terminated;
......
......@@ -150,4 +150,25 @@ CAF_TEST(delegated request with integer result) {
CAF_CHECK_EQUAL(*result, 3);
}
#ifndef CAF_NO_EXCEPTIONS
CAF_TEST(exceptions while processing requests trigger error messages) {
auto worker = sys.spawn([] {
return behavior{
[](int) { throw std::runtime_error(""); },
};
});
run();
auto client = sys.spawn([worker](event_based_actor* self) {
self->request(worker, infinite, 42).then([](int) {
CAF_FAIL("unexpected handler called");
});
});
run_once();
expect((int), from(client).to(worker).with(42));
expect((error), from(worker).to(client).with(sec::runtime_error));
}
#endif // CAF_NO_EXCEPTIONS
CAF_TEST_FIXTURE_SCOPE_END()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment