Commit 9d542932 authored by Dominik Charousset's avatar Dominik Charousset

Capture message text of exceptions if actors die

parent 8d359374
......@@ -54,6 +54,8 @@ is based on [Keep a Changelog](https://keepachangelog.com).
- The `to_string` output for `error` now renders the error code enum by default.
This renders the member functions `actor_system::render` and
`actor_system_config::render` obsolete.
- Actors that die due to an unhandled exception now use `sec::runtime_error`
consistently. This makes `exit_reason::unhandled_exception` obsolete.
### Changed
......
......@@ -104,6 +104,8 @@ int main(int argc, char** argv) {
<< "// DO NOT EDIT: "
"this file is auto-generated by caf-generate-enum-strings.\n"
"// Run the target update-enum-strings if this file is out of sync.\n"
"#include \"caf/config.hpp\"\n\n"
"CAF_PUSH_DEPRECATED_WARNING\n\n"
<< "#include \"" << namespaces[0];
for (size_t i = 1; i < namespaces.size(); ++i)
out << '/' << namespaces[i];
......@@ -142,4 +144,5 @@ int main(int argc, char** argv) {
<< "}\n\n";
for (auto i = namespaces.rbegin(); i != namespaces.rend(); ++i)
out << "} // namespace " << *i << '\n';
out << "\nCAF_POP_WARNINGS\n";
}
......@@ -35,7 +35,7 @@ enum class exit_reason : uint8_t {
/// Indicates that an actor finished execution without error.
normal = 0,
/// Indicates that an actor died because of an unhandled exception.
unhandled_exception,
unhandled_exception [[deprecated("superseded by sec::runtime_error")]],
/// Indicates that the exit reason for this actor is unknown, i.e.,
/// the actor has been terminated and no longer exists.
unknown,
......
......@@ -250,7 +250,8 @@ public:
static void default_exit_handler(pointer ptr, exit_msg& x);
#ifdef CAF_ENABLE_EXCEPTIONS
static error default_exception_handler(pointer ptr, std::exception_ptr& x);
static error default_exception_handler(local_actor* ptr,
std::exception_ptr& x);
#endif // CAF_ENABLE_EXCEPTIONS
// -- constructors and destructors -------------------------------------------
......
......@@ -28,6 +28,7 @@
#include "caf/detail/sync_request_bouncer.hpp"
#include "caf/invoke_message_result.hpp"
#include "caf/logger.hpp"
#include "caf/scheduled_actor.hpp"
#include "caf/telemetry/timer.hpp"
namespace caf {
......@@ -121,7 +122,8 @@ void blocking_actor::launch(execution_unit*, bool, bool hide) {
self->act();
rsn = self->fail_state_;
} catch (...) {
rsn = exit_reason::unhandled_exception;
auto ptr = std::current_exception();
rsn = scheduled_actor::default_exception_handler(self, ptr);
}
try {
self->on_exit();
......
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/exit_reason.hpp"
#include <string>
......@@ -31,3 +35,5 @@ std::string to_string(exit_reason x) {
}
} // namespace caf
CAF_POP_WARNINGS
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/intrusive/inbox_result.hpp"
#include <string>
......@@ -23,3 +27,5 @@ std::string to_string(inbox_result x) {
} // namespace intrusive
} // namespace caf
CAF_POP_WARNINGS
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/intrusive/task_result.hpp"
#include <string>
......@@ -25,3 +29,5 @@ std::string to_string(task_result x) {
} // namespace intrusive
} // namespace caf
CAF_POP_WARNINGS
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/invoke_message_result.hpp"
#include <string>
......@@ -21,3 +25,5 @@ std::string to_string(invoke_message_result x) {
}
} // namespace caf
CAF_POP_WARNINGS
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/message_priority.hpp"
#include <string>
......@@ -19,3 +23,5 @@ std::string to_string(message_priority x) {
}
} // namespace caf
CAF_POP_WARNINGS
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/pec.hpp"
#include <string>
......@@ -61,3 +65,5 @@ std::string to_string(pec x) {
}
} // namespace caf
CAF_POP_WARNINGS
......@@ -96,22 +96,24 @@ void scheduled_actor::default_exit_handler(scheduled_actor* ptr, exit_msg& x) {
}
#ifdef CAF_ENABLE_EXCEPTIONS
error scheduled_actor::default_exception_handler(pointer ptr,
error scheduled_actor::default_exception_handler(local_actor* ptr,
std::exception_ptr& x) {
CAF_ASSERT(x != nullptr);
try {
std::rethrow_exception(x);
} catch (const std::exception& e) {
} catch (std::exception& e) {
auto pretty_type = detail::pretty_type_name(typeid(e));
aout(ptr) << "*** unhandled exception: [id: " << ptr->id()
<< ", name: " << ptr->name()
<< ", exception typeid: " << typeid(e).name() << "]: " << e.what()
<< ", exception typeid: " << pretty_type << "]: " << e.what()
<< std::endl;
return make_error(sec::runtime_error, std::move(pretty_type), e.what());
} catch (...) {
aout(ptr) << "*** unhandled exception: [id: " << ptr->id()
<< ", name: " << ptr->name() << "]: unknown exception"
<< std::endl;
return sec::runtime_error;
}
return sec::runtime_error;
}
#endif // CAF_ENABLE_EXCEPTIONS
......
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/sec.hpp"
#include <string>
......@@ -125,3 +129,5 @@ std::string to_string(sec x) {
}
} // namespace caf
CAF_POP_WARNINGS
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/stream_priority.hpp"
#include <string>
......@@ -25,3 +29,5 @@ std::string to_string(stream_priority x) {
}
} // namespace caf
CAF_POP_WARNINGS
......@@ -63,7 +63,7 @@ CAF_TEST(test_custom_exception_handler) {
catch (...) {
// "fall through"
}
return exit_reason::unhandled_exception;
return sec::runtime_error;
};
scoped_actor self{system};
auto testee1 = self->spawn<monitored>([=](event_based_actor* eb_self) {
......
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/io/basp/message_type.hpp"
#include <string>
......@@ -33,3 +37,5 @@ std::string to_string(message_type x) {
} // namespace basp
} // namespace io
} // namespace caf
CAF_POP_WARNINGS
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/config.hpp"
CAF_PUSH_DEPRECATED_WARNING
#include "caf/io/network/operation.hpp"
#include <string>
......@@ -25,3 +29,5 @@ std::string to_string(operation x) {
} // namespace network
} // namespace io
} // namespace caf
CAF_POP_WARNINGS
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