error handling
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
BlockStorage/repertory/pipeline/pr-master There was a failure building this commit

This commit is contained in:
2025-07-24 08:17:28 -05:00
parent 5fbc27a0ea
commit ce192c086f
5 changed files with 44 additions and 17 deletions

View File

@@ -20,6 +20,7 @@
SOFTWARE. SOFTWARE.
*/ */
#include "comm/curl/curl_shared.hpp" #include "comm/curl/curl_shared.hpp"
#include "utils/error.hpp"
namespace repertory { namespace repertory {
curl_shared::curl_sh_t curl_shared::cache_; curl_shared::curl_sh_t curl_shared::cache_;
@@ -34,12 +35,15 @@ void curl_shared::cleanup() {
auto curl_shared::init() -> bool { auto curl_shared::init() -> bool {
auto res = curl_global_init(CURL_GLOBAL_ALL); auto res = curl_global_init(CURL_GLOBAL_ALL);
if (res != 0) { if (res != 0) {
utils::error::handle_error(function_name,
"failed to initialize curl|result|" +
std::to_string(res));
return false; return false;
} }
auto *cache = curl_share_init(); auto *cache = curl_share_init();
if (cache == nullptr) { if (cache == nullptr) {
curl_global_cleanup(); utils::error::handle_error(function_name, "failed to create curl share");
return false; return false;
} }
cache_.reset(cache); cache_.reset(cache);

View File

@@ -381,6 +381,7 @@ auto fuse_base::init_impl(struct fuse_conn_info *conn) -> void * {
if (not console_enabled_ && not repertory::project_initialize()) { if (not console_enabled_ && not repertory::project_initialize()) {
utils::error::raise_error(function_name, "failed to initialize repertory"); utils::error::raise_error(function_name, "failed to initialize repertory");
event_system::instance().raise<unmount_requested>(function_name); event_system::instance().raise<unmount_requested>(function_name);
repertory::project_cleanup();
} }
return this; return this;

View File

@@ -39,6 +39,7 @@
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "initialize.hpp" #include "initialize.hpp"
#include "utils/error.hpp"
#if defined(PROJECT_REQUIRE_ALPINE) && !defined(PROJECT_IS_MINGW) #if defined(PROJECT_REQUIRE_ALPINE) && !defined(PROJECT_IS_MINGW)
#include "utils/path.hpp" #include "utils/path.hpp"
@@ -48,6 +49,11 @@
#include "comm/curl/curl_shared.hpp" #include "comm/curl/curl_shared.hpp"
#endif // defined(PROJECT_ENABLE_CURL) #endif // defined(PROJECT_ENABLE_CURL)
namespace {
bool curl_initialized{false};
bool sqlite3_initialized{false};
} // namespace
namespace repertory { namespace repertory {
auto project_initialize() -> bool { auto project_initialize() -> bool {
#if defined(PROJECT_REQUIRE_ALPINE) && !defined(PROJECT_IS_MINGW) #if defined(PROJECT_REQUIRE_ALPINE) && !defined(PROJECT_IS_MINGW)
@@ -65,38 +71,39 @@ auto project_initialize() -> bool {
#endif // defined(PROJECT_REQUIRE_ALPINE) && !defined (PROJECT_IS_MINGW) #endif // defined(PROJECT_REQUIRE_ALPINE) && !defined (PROJECT_IS_MINGW)
spdlog::drop_all(); spdlog::drop_all();
spdlog::flush_every(std::chrono::seconds(10)); spdlog::flush_every(std::chrono::seconds(5));
spdlog::set_pattern("%Y-%m-%d|%T.%e|%^%l%$|%v"); spdlog::set_pattern("%Y-%m-%d|%T.%e|%^%l%$|%v");
#if defined(PROJECT_ENABLE_LIBSODIUM) #if defined(PROJECT_ENABLE_LIBSODIUM)
{ if (sodium_init() == -1) {
if (sodium_init() == -1) { utils::error::handle_error(function_name, "failed to initialize sodium");
return false; return false;
}
} }
#endif // defined(PROJECT_ENABLE_LIBSODIUM) #endif // defined(PROJECT_ENABLE_LIBSODIUM)
#if defined(PROJECT_ENABLE_OPENSSL) #if defined(PROJECT_ENABLE_OPENSSL)
{ SSL_library_init();
SSL_library_init();
}
#endif // defined(PROJECT_ENABLE_OPENSSL) #endif // defined(PROJECT_ENABLE_OPENSSL)
#if defined(PROJECT_ENABLE_CURL) #if defined(PROJECT_ENABLE_CURL)
if (not curl_shared::init()) { if (not curl_shared::init()) {
return false; return false;
} }
curl_initialized = true;
#endif // defined(PROJECT_ENABLE_CURL) #endif // defined(PROJECT_ENABLE_CURL)
#if defined(PROJECT_ENABLE_SQLITE) #if defined(PROJECT_ENABLE_SQLITE)
{ {
auto res = sqlite3_initialize(); auto res = sqlite3_initialize();
if (res != SQLITE_OK) { if (res != SQLITE_OK) {
#if defined(PROJECT_ENABLE_CURL) utils::error::handle_error(function_name,
curl_shared::cleanup(); "failed to initialize sqlite3|result|" +
#endif // defined(PROJECT_ENABLE_CURL) std::to_string(res));
return false; return false;
} }
sqlite3_initialized = true;
} }
#endif // defined(PROJECT_ENABLE_SQLITE) #endif // defined(PROJECT_ENABLE_SQLITE)
@@ -105,12 +112,17 @@ auto project_initialize() -> bool {
void project_cleanup() { void project_cleanup() {
#if defined(PROJECT_ENABLE_CURL) #if defined(PROJECT_ENABLE_CURL)
curl_shared::cleanup(); if (curl_initialized) {
curl_shared::cleanup();
}
#endif // defined(PROJECT_ENABLE_CURL) #endif // defined(PROJECT_ENABLE_CURL)
#if defined(PROJECT_ENABLE_SQLITE) #if defined(PROJECT_ENABLE_SQLITE)
sqlite3_shutdown(); if (sqlite3_initialized) {
sqlite3_shutdown();
}
#endif // defined(PROJECT_ENABLE_SQLITE) #endif // defined(PROJECT_ENABLE_SQLITE)
spdlog::shutdown(); spdlog::shutdown();
} }
} // namespace repertory } // namespace repertory

View File

@@ -38,6 +38,7 @@ auto main(int argc, char **argv) -> int {
if (not repertory::project_initialize()) { if (not repertory::project_initialize()) {
std::cerr << "fatal: failed to initialize repertory" << std::endl; std::cerr << "fatal: failed to initialize repertory" << std::endl;
repertory::project_cleanup();
return -1; return -1;
} }

View File

@@ -25,23 +25,32 @@
#include "initialize.hpp" #include "initialize.hpp"
#include "test_common.hpp" #include "test_common.hpp"
#include "utils/error.hpp"
using namespace repertory; using namespace repertory;
int PROJECT_TEST_RESULT{0}; int PROJECT_TEST_RESULT{0};
auto main(int argc, char **argv) -> int { auto main(int argc, char **argv) -> int {
REPERTORY_USES_FUNCTION_NAME();
#if defined(PROJECT_ENABLE_BACKWARD_CPP) #if defined(PROJECT_ENABLE_BACKWARD_CPP)
static backward::SignalHandling sh; static backward::SignalHandling sh;
#endif // defined(PROJECT_ENABLE_BACKWARD_CPP) #endif // defined(PROJECT_ENABLE_BACKWARD_CPP)
if (not repertory::project_initialize()) { if (not repertory::project_initialize()) {
std::cerr << "fatal: failed to initialize repertory" << std::endl; repertory::project_cleanup();
return -1; return -1;
} }
::testing::InitGoogleTest(&argc, argv); try {
PROJECT_TEST_RESULT = RUN_ALL_TESTS(); ::testing::InitGoogleTest(&argc, argv);
PROJECT_TEST_RESULT = RUN_ALL_TESTS();
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {
utils::error::handle_exception(function_name);
}
repertory::project_cleanup(); repertory::project_cleanup();