[bug] Sia provider error responses are not being logged #30

This commit is contained in:
Scott E. Graves 2024-12-31 13:34:08 -06:00
parent 1a11d55782
commit 36908f7da9

View File

@ -197,6 +197,9 @@ auto sia_provider::get_directory_items_impl(const std::string &api_path,
auto sia_provider::get_file(const std::string &api_path, api_file &file) const auto sia_provider::get_file(const std::string &api_path, api_file &file) const
-> api_error { -> api_error {
REPERTORY_USES_FUNCTION_NAME();
try {
json file_data{}; json file_data{};
auto res = get_object_info(api_path, file_data); auto res = get_object_info(api_path, file_data);
if (res != api_error::success) { if (res != api_error::success) {
@ -204,8 +207,8 @@ auto sia_provider::get_file(const std::string &api_path, api_file &file) const
} }
auto slabs = file_data["object"]["Slabs"]; auto slabs = file_data["object"]["Slabs"];
auto size = auto size = std::accumulate(
std::accumulate(slabs.begin(), slabs.end(), std::uint64_t(0U), slabs.begin(), slabs.end(), std::uint64_t(0U),
[](std::uint64_t total_size, [](std::uint64_t total_size,
const nlohmann::json &slab) -> std::uint64_t { const nlohmann::json &slab) -> std::uint64_t {
return total_size + slab["Length"].get<std::uint64_t>(); return total_size + slab["Length"].get<std::uint64_t>();
@ -221,6 +224,12 @@ auto sia_provider::get_file(const std::string &api_path, api_file &file) const
} }
return api_error::success; return api_error::success;
} catch (const std::exception &e) {
utils::error::raise_api_path_error(function_name, api_path, e,
"failed to get file");
}
return api_error::error;
} }
auto sia_provider::get_file_list(api_file_list &list, auto sia_provider::get_file_list(api_file_list &list,
@ -341,6 +350,7 @@ auto sia_provider::get_object_list(const std::string &api_path,
nlohmann::json &object_list) const -> bool { nlohmann::json &object_list) const -> bool {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try {
curl::requests::http_get get{}; curl::requests::http_get get{};
get.allow_timeout = true; get.allow_timeout = true;
get.path = "/api/bus/objects" + api_path + "/"; get.path = "/api/bus/objects" + api_path + "/";
@ -374,6 +384,12 @@ auto sia_provider::get_object_list(const std::string &api_path,
} }
return true; return true;
} catch (const std::exception &e) {
utils::error::raise_api_path_error(function_name, api_path, e,
"failed to get object list");
}
return false;
} }
auto sia_provider::get_total_drive_space() const -> std::uint64_t { auto sia_provider::get_total_drive_space() const -> std::uint64_t {
@ -404,8 +420,8 @@ auto sia_provider::get_total_drive_space() const -> std::uint64_t {
} }
if (response_code != http_error_codes::ok) { if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error( utils::error::raise_error(
function_name, api_path, response_code, function_name, response_code,
fmt::format("failed to get total drive space|response|{}", fmt::format("failed to get total drive space|response|{}",
error_data)); error_data));
return 0U; return 0U;
@ -424,6 +440,7 @@ auto sia_provider::is_directory(const std::string &api_path, bool &exists) const
-> api_error { -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try {
if (api_path == "/") { if (api_path == "/") {
exists = true; exists = true;
return api_error::success; return api_error::success;
@ -431,7 +448,6 @@ auto sia_provider::is_directory(const std::string &api_path, bool &exists) const
exists = false; exists = false;
try {
json object_list{}; json object_list{};
if (not get_object_list(utils::path::get_parent_api_path(api_path), if (not get_object_list(utils::path::get_parent_api_path(api_path),
object_list)) { object_list)) {
@ -446,8 +462,8 @@ auto sia_provider::is_directory(const std::string &api_path, bool &exists) const
}) != object_list.at("entries").end(); }) != object_list.at("entries").end();
return api_error::success; return api_error::success;
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::raise_api_path_error(function_name, api_path, e, utils::error::raise_api_path_error(
"failed to determine path is directory"); function_name, api_path, e, "failed to determine if path is directory");
} }
return api_error::error; return api_error::error;
@ -457,12 +473,12 @@ auto sia_provider::is_file(const std::string &api_path, bool &exists) const
-> api_error { -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try {
exists = false; exists = false;
if (api_path == "/") { if (api_path == "/") {
return api_error::success; return api_error::success;
} }
try {
json file_data{}; json file_data{};
auto res = get_object_info(api_path, file_data); auto res = get_object_info(api_path, file_data);
if (res == api_error::item_not_found) { if (res == api_error::item_not_found) {
@ -477,7 +493,7 @@ auto sia_provider::is_file(const std::string &api_path, bool &exists) const
return api_error::success; return api_error::success;
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::raise_api_path_error(function_name, api_path, e, utils::error::raise_api_path_error(function_name, api_path, e,
"failed to determine path is directory"); "failed to determine if path is file");
} }
return api_error::error; return api_error::error;
@ -513,8 +529,8 @@ auto sia_provider::is_online() const -> bool {
} }
if (response_code != http_error_codes::ok) { if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error( utils::error::raise_error(
function_name, api_path, response_code, function_name, response_code,
fmt::format("failed to determine if provider is online|response|{}", fmt::format("failed to determine if provider is online|response|{}",
error_data)); error_data));
return false; return false;
@ -535,6 +551,7 @@ auto sia_provider::read_file_bytes(const std::string &api_path,
stop_type &stop_requested) -> api_error { stop_type &stop_requested) -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try {
curl::requests::http_get get{}; curl::requests::http_get get{};
get.path = "/api/worker/objects" + api_path; get.path = "/api/worker/objects" + api_path;
get.query["bucket"] = get_bucket(get_sia_config()); get.query["bucket"] = get_bucket(get_sia_config());
@ -546,7 +563,7 @@ auto sia_provider::read_file_bytes(const std::string &api_path,
buffer = data; buffer = data;
}; };
auto res = api_error::comm_error; auto res{api_error::comm_error};
for (std::uint32_t idx = 0U; for (std::uint32_t idx = 0U;
not stop_requested && res != api_error::success && not stop_requested && res != api_error::success &&
idx < get_config().get_retry_read_count() + 1U; idx < get_config().get_retry_read_count() + 1U;
@ -584,6 +601,12 @@ auto sia_provider::read_file_bytes(const std::string &api_path,
} }
return res; return res;
} catch (const std::exception &e) {
utils::error::raise_api_path_error(function_name, e, api_path,
"failed to read file bytes");
}
return api_error::error;
} }
auto sia_provider::remove_directory_impl(const std::string &api_path) auto sia_provider::remove_directory_impl(const std::string &api_path)
@ -614,8 +637,9 @@ auto sia_provider::remove_directory_impl(const std::string &api_path)
} }
if (response_code != http_error_codes::ok) { if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error(function_name, api_path, response_code, utils::error::raise_api_path_error(
fmt::format("failed to remove directory|response|", error_data); function_name, api_path, response_code,
fmt::format("failed to remove directory|response|{}", error_data));
return api_error::comm_error; return api_error::comm_error;
} }
@ -663,6 +687,7 @@ auto sia_provider::rename_file(const std::string &from_api_path,
const std::string &to_api_path) -> api_error { const std::string &to_api_path) -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try {
curl::requests::http_post post{}; curl::requests::http_post post{};
post.json = nlohmann::json({ post.json = nlohmann::json({
{"from", from_api_path}, {"from", from_api_path},
@ -685,8 +710,8 @@ auto sia_provider::rename_file(const std::string &from_api_path,
stop_type stop_requested{}; stop_type stop_requested{};
if (not get_comm().make_request(post, response_code, stop_requested)) { if (not get_comm().make_request(post, response_code, stop_requested)) {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
function_name, fmt::format("{}|{}", from_api_path, to_api_path), api_error::comm_error, function_name, fmt::format("{}|{}", from_api_path, to_api_path),
"failed to rename file"); api_error::comm_error, "failed to rename file");
return api_error::comm_error; return api_error::comm_error;
} }
@ -700,6 +725,12 @@ auto sia_provider::rename_file(const std::string &from_api_path,
} }
return get_db().rename_item_meta(from_api_path, to_api_path); return get_db().rename_item_meta(from_api_path, to_api_path);
} catch (const std::exception &e) {
utils::error::raise_api_path_error(function_name, e, api_path,
"failed to rename file");
}
return api_error::error;
} }
auto sia_provider::start(api_item_added_callback api_item_added, auto sia_provider::start(api_item_added_callback api_item_added,