From 71c3ab61be45ab85ba5b42365d2ec1eebf1cb27b Mon Sep 17 00:00:00 2001 From: sha512sum Date: Wed, 3 Jul 2024 15:19:50 +0000 Subject: [PATCH] Use cxxabi to print execptions types --- include/cserver/engine/components.hpp | 13 +++++++++++-- include/cserver/engine/not_implemented.hpp | 5 +---- .../cserver/server/handlers/http_handler_base.hpp | 6 ++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/include/cserver/engine/components.hpp b/include/cserver/engine/components.hpp index 71710d7..2e51ce7 100644 --- a/include/cserver/engine/components.hpp +++ b/include/cserver/engine/components.hpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include namespace cserver { @@ -205,10 +207,17 @@ inline constexpr auto InitComponents(T& ccontext, int ac, const char** av) -> vo Get(context.storage).emplace(currentContext); }; } catch(std::exception& error) { - fmt::println("An error occurred while initializing component {}: {}", static_cast(Current::kName), error.what()); + auto typeName = boost::core::demangle(__cxxabiv1::__cxa_current_exception_type()->name()); + fmt::println("{} initialisation:\n terminating due to uncaught exception of type {}: {}", + static_cast(Current::kName), + typeName, + error.what()); ioContext.stop(); } catch(...) { - fmt::println("An unknown error occurred while initializing component {}", static_cast(Current::kName)); + auto typeName = boost::core::demangle(__cxxabiv1::__cxa_current_exception_type()->name()); + fmt::println("{} initialisation:\n terminating due to uncaught exception of type {}", + static_cast(Current::kName), + typeName); ioContext.stop(); }; auto& componentInitFlag = GetInitFlagFor(ioContext); diff --git a/include/cserver/engine/not_implemented.hpp b/include/cserver/engine/not_implemented.hpp index f54eafb..5b29eac 100644 --- a/include/cserver/engine/not_implemented.hpp +++ b/include/cserver/engine/not_implemented.hpp @@ -1,14 +1,11 @@ #pragma once #include -#include -#include namespace cserver::engine { struct NotImplemented : std::runtime_error { - NotImplemented(std::string context) : - std::runtime_error{fmt::format(FMT_COMPILE("Not Implemented Error [{}]"), context)} {}; + using std::runtime_error::runtime_error; }; } // namespace cserver::engine diff --git a/include/cserver/server/handlers/http_handler_base.hpp b/include/cserver/server/handlers/http_handler_base.hpp index 74c08f0..fd26993 100644 --- a/include/cserver/server/handlers/http_handler_base.hpp +++ b/include/cserver/server/handlers/http_handler_base.hpp @@ -23,9 +23,11 @@ struct HttpHandlerBase : ComponentBase { try { co_return co_await std::forward(self).HandleRequestThrow(std::move(request)); } catch(const std::exception& err) { - self.logging.template Warning<"Error in handler with default name {}: {}">(T::kName, err.what()); + auto typeName = boost::core::demangle(__cxxabiv1::__cxa_current_exception_type()->name()); + self.logging.template Warning<"In handler with default name {} uncaught exception of type {}: {}">(T::kName, typeName, err.what()); } catch(...) { - self.logging.template Warning<"Error in handler with default name {}: Unknown Error">(T::kName); + auto typeName = boost::core::demangle(__cxxabiv1::__cxa_current_exception_type()->name()); + self.logging.template Warning<"In handler with default name {} uncaught exception of type {}">(T::kName, typeName); }; co_return http::HttpResponse{.statusCode = 500, .statusMessage = "Internal Server Error", .body = "Internal Server Error"}; };