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

View File

@@ -39,6 +39,7 @@
#include "spdlog/spdlog.h"
#include "initialize.hpp"
#include "utils/error.hpp"
#if defined(PROJECT_REQUIRE_ALPINE) && !defined(PROJECT_IS_MINGW)
#include "utils/path.hpp"
@@ -48,6 +49,11 @@
#include "comm/curl/curl_shared.hpp"
#endif // defined(PROJECT_ENABLE_CURL)
namespace {
bool curl_initialized{false};
bool sqlite3_initialized{false};
} // namespace
namespace repertory {
auto project_initialize() -> bool {
#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)
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");
#if defined(PROJECT_ENABLE_LIBSODIUM)
{
if (sodium_init() == -1) {
return false;
}
if (sodium_init() == -1) {
utils::error::handle_error(function_name, "failed to initialize sodium");
return false;
}
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
#if defined(PROJECT_ENABLE_OPENSSL)
{
SSL_library_init();
}
SSL_library_init();
#endif // defined(PROJECT_ENABLE_OPENSSL)
#if defined(PROJECT_ENABLE_CURL)
if (not curl_shared::init()) {
return false;
}
curl_initialized = true;
#endif // defined(PROJECT_ENABLE_CURL)
#if defined(PROJECT_ENABLE_SQLITE)
{
auto res = sqlite3_initialize();
if (res != SQLITE_OK) {
#if defined(PROJECT_ENABLE_CURL)
curl_shared::cleanup();
#endif // defined(PROJECT_ENABLE_CURL)
utils::error::handle_error(function_name,
"failed to initialize sqlite3|result|" +
std::to_string(res));
return false;
}
sqlite3_initialized = true;
}
#endif // defined(PROJECT_ENABLE_SQLITE)
@@ -105,12 +112,17 @@ auto project_initialize() -> bool {
void project_cleanup() {
#if defined(PROJECT_ENABLE_CURL)
curl_shared::cleanup();
if (curl_initialized) {
curl_shared::cleanup();
}
#endif // defined(PROJECT_ENABLE_CURL)
#if defined(PROJECT_ENABLE_SQLITE)
sqlite3_shutdown();
if (sqlite3_initialized) {
sqlite3_shutdown();
}
#endif // defined(PROJECT_ENABLE_SQLITE)
spdlog::shutdown();
}
} // namespace repertory

View File

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

View File

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