updated build system

This commit is contained in:
Scott E. Graves 2025-02-19 16:39:40 -06:00
parent ff693f907b
commit 488ce4bfcd
2 changed files with 86 additions and 62 deletions

View File

@ -72,89 +72,37 @@ protected:
i_exception_handler() = default; i_exception_handler() = default;
}; };
struct iostream_exception_handler final : i_exception_handler { struct iostream_exception_handler final : public i_exception_handler {
#if defined(PROJECT_ENABLE_V2_ERRORS) #if defined(PROJECT_ENABLE_V2_ERRORS)
void handle_debug(std::string_view function_name, void handle_debug(std::string_view function_name,
std::string_view msg) const override { std::string_view msg) const override;
std::cout << create_error_message(function_name,
{
"debug",
msg,
})
<< std::endl;
}
#endif // defined(PROJECT_ENABLE_V2_ERRORS) #endif // defined(PROJECT_ENABLE_V2_ERRORS)
void handle_error(std::string_view function_name, void handle_error(std::string_view function_name,
std::string_view msg) const override { std::string_view msg) const override;
std::cerr << create_error_message(function_name,
{
"error",
msg,
})
<< std::endl;
}
void handle_exception(std::string_view function_name) const override { void handle_exception(std::string_view function_name) const override;
std::cerr << create_error_message(function_name,
{
"error",
"exception",
"unknown",
})
<< std::endl;
}
void handle_exception(std::string_view function_name, void handle_exception(std::string_view function_name,
const std::exception &ex) const override { const std::exception &ex) const override;
std::cerr << create_error_message(
function_name,
{
"error",
"exception",
(ex.what() == nullptr ? "unknown" : ex.what()),
})
<< std::endl;
}
#if defined(PROJECT_ENABLE_V2_ERRORS) #if defined(PROJECT_ENABLE_V2_ERRORS)
void handle_info(std::string_view function_name, void handle_info(std::string_view function_name,
std::string_view msg) const override { std::string_view msg) const override;
std::cout << create_error_message(function_name,
{
"info",
msg,
})
<< std::endl;
}
void handle_trace(std::string_view function_name, void handle_trace(std::string_view function_name,
std::string_view msg) const override { std::string_view msg) const override;
std::cout << create_error_message(function_name,
{
"trace",
msg,
})
<< std::endl;
}
void handle_warn(std::string_view function_name, void handle_warn(std::string_view function_name,
std::string_view msg) const override { std::string_view msg) const override;
std::cout << create_error_message(function_name,
{
"warn",
msg,
})
<< std::endl;
}
#endif // defined(PROJECT_ENABLE_V2_ERRORS) #endif // defined(PROJECT_ENABLE_V2_ERRORS)
}; };
inline const iostream_exception_handler default_exception_handler{}; inline const iostream_exception_handler default_exception_handler{};
#if defined(PROJECT_ENABLE_TESTING)
extern std::atomic<const i_exception_handler *> exception_handler; extern std::atomic<const i_exception_handler *> exception_handler;
#if defined(PROJECT_ENABLE_TESTING)
[[nodiscard]] inline auto get_exception_handler() [[nodiscard]] inline auto get_exception_handler()
-> const i_exception_handler * { -> const i_exception_handler * {
return exception_handler; return exception_handler;

View File

@ -22,6 +22,82 @@
#include "utils/error.hpp" #include "utils/error.hpp"
namespace monitarr::utils::error { namespace monitarr::utils::error {
#if defined(PROJECT_ENABLE_V2_ERRORS)
void iostream_exception_handler::handle_debug(std::string_view function_name,
std::string_view msg) const {
std::cout << create_error_message({
"debug",
function_name,
msg,
})
<< std::endl;
}
#endif // defined(PROJECT_ENABLE_V2_ERRORS)
void iostream_exception_handler::handle_error(std::string_view function_name,
std::string_view msg) const {
std::cerr << create_error_message({
"error",
function_name,
msg,
})
<< std::endl;
}
void iostream_exception_handler::handle_exception(
std::string_view function_name) const {
std::cerr << create_error_message({
"error",
function_name,
"exception",
"unknown",
})
<< std::endl;
}
void iostream_exception_handler::handle_exception(
std::string_view function_name, const std::exception &ex) const {
std::cerr << create_error_message({
"error",
function_name,
"exception",
(ex.what() == nullptr ? "unknown" : ex.what()),
})
<< std::endl;
}
#if defined(PROJECT_ENABLE_V2_ERRORS)
void iostream_exception_handler::handle_info(std::string_view function_name,
std::string_view msg) const {
std::cout << create_error_message({
"info",
function_name,
msg,
})
<< std::endl;
}
void iostream_exception_handler::handle_trace(std::string_view function_name,
std::string_view msg) const {
std::cout << create_error_message({
"trace",
function_name,
msg,
})
<< std::endl;
}
void iostream_exception_handler::handle_warn(std::string_view function_name,
std::string_view msg) const {
std::cout << create_error_message({
"warn",
function_name,
msg,
})
<< std::endl;
}
#endif // defined(PROJECT_ENABLE_V2_ERRORS)
std::atomic<const i_exception_handler *> exception_handler{ std::atomic<const i_exception_handler *> exception_handler{
&default_exception_handler}; &default_exception_handler};
@ -40,7 +116,7 @@ auto create_error_message(std::vector<std::string_view> items) -> std::string {
auto create_error_message(std::string_view function_name, auto create_error_message(std::string_view function_name,
std::vector<std::string_view> items) -> std::string { std::vector<std::string_view> items) -> std::string {
items.insert(items.begin(), function_name); items.insert(std::next(items.begin()), function_name);
return create_error_message(items); return create_error_message(items);
} }