diff --git a/scripts/env.sh b/scripts/env.sh index cd0c8df..ce8873f 100755 --- a/scripts/env.sh +++ b/scripts/env.sh @@ -358,6 +358,7 @@ echo " Company name: ${PROJECT_COMPANY_NAME}" echo " Copyright: ${PROJECT_COPYRIGHT}" echo " Description: ${PROJECT_DESC}" echo " Dist dir: ${PROJECT_DIST_DIR}" +echo " Enable v2 errors: ${PROJECT_ENABLE_V2_ERRORS}" echo " External build root: ${PROJECT_EXTERNAL_BUILD_ROOT}" echo " File part: ${PROJECT_FILE_PART}" echo " Is ARM64: ${PROJECT_IS_ARM64}" diff --git a/support/include/utils/error.hpp b/support/include/utils/error.hpp index 822fc90..642b4c3 100644 --- a/support/include/utils/error.hpp +++ b/support/include/utils/error.hpp @@ -119,6 +119,9 @@ struct spdlog_exception_handler final : public i_exception_handler { void handle_warn(std::string_view function_name, std::string_view msg) const override; + +private: + iostream_exception_handler fallback{}; }; #endif // defined(PROJECT_ENABLE_SPDLOG) && defined(PROJECT_ENABLE_V2_ERRORS) diff --git a/support/src/utils/error_handler.cpp b/support/src/utils/error_handler.cpp index d792180..1f08cf7 100644 --- a/support/src/utils/error_handler.cpp +++ b/support/src/utils/error_handler.cpp @@ -105,8 +105,12 @@ void iostream_exception_handler::handle_warn(std::string_view function_name, #if defined(PROJECT_ENABLE_SPDLOG) && defined(PROJECT_ENABLE_V2_ERRORS) void spdlog_exception_handler::handle_debug(std::string_view function_name, std::string_view msg) const { - spdlog::get("console")->debug( - utils::error::create_error_message(function_name, {msg})); + auto console = spdlog::get("console"); + if (console) { + console->debug(utils::error::create_error_message(function_name, {msg})); + } else { + fallback.handle_debug(function_name, msg); + } auto file = spdlog::get("file"); if (not file) { @@ -118,8 +122,12 @@ void spdlog_exception_handler::handle_debug(std::string_view function_name, void spdlog_exception_handler::handle_error(std::string_view function_name, std::string_view msg) const { - spdlog::get("console")->error( - utils::error::create_error_message(function_name, {msg})); + auto console = spdlog::get("console"); + if (console) { + console->error(utils::error::create_error_message(function_name, {msg})); + } else { + fallback.handle_error(function_name, msg); + } auto file = spdlog::get("file"); if (not file) { @@ -131,11 +139,16 @@ void spdlog_exception_handler::handle_error(std::string_view function_name, void spdlog_exception_handler::handle_exception( std::string_view function_name) const { - spdlog::get("console")->error( - utils::error::create_error_message(function_name, { - "exception", - "unknown exception", - })); + auto console = spdlog::get("console"); + if (console) { + console->error(utils::error::create_error_message(function_name, + { + "exception", + "unknown exception", + })); + } else { + fallback.handle_exception(function_name); + } auto file = spdlog::get("file"); if (not file) { @@ -151,11 +164,16 @@ void spdlog_exception_handler::handle_exception( void spdlog_exception_handler::handle_exception( std::string_view function_name, const std::exception &ex) const { - spdlog::get("console")->error(utils::error::create_error_message( - function_name, { - "exception", - (ex.what() == nullptr ? "unknown" : ex.what()), - })); + auto console = spdlog::get("console"); + if (console) { + console->error(utils::error::create_error_message( + function_name, { + "exception", + (ex.what() == nullptr ? "unknown" : ex.what()), + })); + } else { + fallback.handle_exception(function_name, ex); + } auto file = spdlog::get("file"); if (not file) { @@ -171,8 +189,12 @@ void spdlog_exception_handler::handle_exception( void spdlog_exception_handler::handle_info(std::string_view function_name, std::string_view msg) const { - spdlog::get("console")->info( - utils::error::create_error_message(function_name, {msg})); + auto console = spdlog::get("console"); + if (console) { + console->info(utils::error::create_error_message(function_name, {msg})); + } else { + fallback.handle_info(function_name, msg); + } auto file = spdlog::get("file"); if (not file) { @@ -184,8 +206,12 @@ void spdlog_exception_handler::handle_info(std::string_view function_name, void spdlog_exception_handler::handle_trace(std::string_view function_name, std::string_view msg) const { - spdlog::get("console")->trace( - utils::error::create_error_message(function_name, {msg})); + auto console = spdlog::get("console"); + if (console) { + console->trace(utils::error::create_error_message(function_name, {msg})); + } else { + fallback.handle_trace(function_name, msg); + } auto file = spdlog::get("file"); if (not file) { @@ -197,8 +223,12 @@ void spdlog_exception_handler::handle_trace(std::string_view function_name, void spdlog_exception_handler::handle_warn(std::string_view function_name, std::string_view msg) const { - spdlog::get("console")->warn( - utils::error::create_error_message(function_name, {msg})); + auto console = spdlog::get("console"); + if (console) { + console->warn(utils::error::create_error_message(function_name, {msg})); + } else { + fallback.handle_warn(function_name, msg); + } auto file = spdlog::get("file"); if (not file) {