Use cxxabi to print execptions types
This commit is contained in:
parent
e2510d3b64
commit
71c3ab61be
3 changed files with 16 additions and 8 deletions
|
@ -3,6 +3,8 @@
|
||||||
#include <cserver/engine/coroutine.hpp>
|
#include <cserver/engine/coroutine.hpp>
|
||||||
#include <utempl/utils.hpp>
|
#include <utempl/utils.hpp>
|
||||||
#include <utempl/loopholes/counter.hpp>
|
#include <utempl/loopholes/counter.hpp>
|
||||||
|
#include <cxxabi.h>
|
||||||
|
#include <boost/core/demangle.hpp>
|
||||||
|
|
||||||
namespace cserver {
|
namespace cserver {
|
||||||
|
|
||||||
|
@ -205,10 +207,17 @@ inline constexpr auto InitComponents(T& ccontext, int ac, const char** av) -> vo
|
||||||
Get<Is>(context.storage).emplace(currentContext);
|
Get<Is>(context.storage).emplace(currentContext);
|
||||||
};
|
};
|
||||||
} catch(std::exception& error) {
|
} catch(std::exception& error) {
|
||||||
fmt::println("An error occurred while initializing component {}: {}", static_cast<std::string_view>(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<std::string_view>(Current::kName),
|
||||||
|
typeName,
|
||||||
|
error.what());
|
||||||
ioContext.stop();
|
ioContext.stop();
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
fmt::println("An unknown error occurred while initializing component {}", static_cast<std::string_view>(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<std::string_view>(Current::kName),
|
||||||
|
typeName);
|
||||||
ioContext.stop();
|
ioContext.stop();
|
||||||
};
|
};
|
||||||
auto& componentInitFlag = GetInitFlagFor<AsyncConditionVariable, Is>(ioContext);
|
auto& componentInitFlag = GetInitFlagFor<AsyncConditionVariable, Is>(ioContext);
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <fmt/format.h>
|
|
||||||
#include <fmt/compile.h>
|
|
||||||
|
|
||||||
namespace cserver::engine {
|
namespace cserver::engine {
|
||||||
|
|
||||||
struct NotImplemented : std::runtime_error {
|
struct NotImplemented : std::runtime_error {
|
||||||
NotImplemented(std::string context) :
|
using std::runtime_error::runtime_error;
|
||||||
std::runtime_error{fmt::format(FMT_COMPILE("Not Implemented Error [{}]"), context)} {};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace cserver::engine
|
} // namespace cserver::engine
|
||||||
|
|
|
@ -23,9 +23,11 @@ struct HttpHandlerBase : ComponentBase {
|
||||||
try {
|
try {
|
||||||
co_return co_await std::forward<Self>(self).HandleRequestThrow(std::move(request));
|
co_return co_await std::forward<Self>(self).HandleRequestThrow(std::move(request));
|
||||||
} catch(const std::exception& err) {
|
} 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(...) {
|
} 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"};
|
co_return http::HttpResponse{.statusCode = 500, .statusMessage = "Internal Server Error", .body = "Internal Server Error"};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue