mirror of
https://github.com/davidallendj/gdpm.git
synced 2025-12-20 03:27:02 -07:00
Fix fmt 10 breaking logging and changed printing format
This commit is contained in:
parent
5bdc605f0b
commit
431be7914c
10 changed files with 114 additions and 130 deletions
|
|
@ -173,7 +173,7 @@ namespace gdpm::cache{
|
|||
sql += "COMMIT;\n";
|
||||
rc = sqlite3_exec(db, sql.c_str(), callback, (void*)&p_vector, &errmsg);
|
||||
if(rc != SQLITE_OK){
|
||||
error error(constants::error::SQLITE_ERR, std::format(
|
||||
error error(ec::SQLITE_ERR, std::format(
|
||||
"cache::get_package_info_by_id::sqlite3_exec(): {}", errmsg
|
||||
));
|
||||
sqlite3_free(errmsg);
|
||||
|
|
|
|||
|
|
@ -262,8 +262,7 @@ namespace gdpm::config{
|
|||
else if(property == "verbosity") config.verbose = std::stoi(value);
|
||||
else if(property == "style") config.style = to_style(value);
|
||||
else{
|
||||
return log::error_rc(error(
|
||||
constants::error::INVALID_CONFIG,
|
||||
return log::error_rc(error(ec::INVALID_CONFIG,
|
||||
"Could not find property"
|
||||
));
|
||||
}
|
||||
|
|
@ -331,7 +330,7 @@ namespace gdpm::config{
|
|||
|
||||
|
||||
error validate(const rapidjson::Document& doc){
|
||||
error error(constants::error::INVALID_CONFIG, "");
|
||||
error error(ec::INVALID_CONFIG, "");
|
||||
if(!doc.IsObject()){
|
||||
error.set_message("Document is not a JSON object.");
|
||||
return error;
|
||||
|
|
@ -344,7 +343,7 @@ namespace gdpm::config{
|
|||
error.set_message("Key `remote_sources` is not a JSON object.");
|
||||
return error;
|
||||
}
|
||||
error.set_code(constants::error::NONE);
|
||||
error.set_code(ec::NONE);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
|
|
|||
30
src/http.cpp
30
src/http.cpp
|
|
@ -4,6 +4,7 @@
|
|||
#include "log.hpp"
|
||||
#include "error.hpp"
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <curl/curl.h>
|
||||
#include <curl/easy.h>
|
||||
#include <curl/multi.h>
|
||||
|
|
@ -74,9 +75,7 @@ namespace gdpm::http{
|
|||
curl_slist_free_all(list);
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &r.code);
|
||||
if(res != CURLE_OK && params.verbose > 0)
|
||||
log::error(ec::LIBCURL_ERR,
|
||||
std::format("http::context::request::curl_easy_perform(): {}", curl_easy_strerror(res))
|
||||
);
|
||||
log::error("http::context::request::curl_easy_perform(): {}", (long)curl_easy_strerror(res));
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
|
|
@ -91,7 +90,7 @@ namespace gdpm::http{
|
|||
const http::request& params
|
||||
){
|
||||
if(cm == nullptr){
|
||||
log::error(error(PRECONDITION_FAILED,
|
||||
log::error(error(ec::PRECONDITION_FAILED,
|
||||
"http::multi::make_downloads(): multi client not initialized.")
|
||||
);
|
||||
}
|
||||
|
|
@ -173,7 +172,8 @@ namespace gdpm::http{
|
|||
log::println("transfers left: {}", transfers_left);
|
||||
cres = curl_multi_remove_handle(cm, eh);
|
||||
if(cres != CURLM_OK){
|
||||
log::error("http::context::execute(): curl_multi_remove_handle() returned error {}", cres);
|
||||
log::error(error(ec::LIBCURL_ERR,
|
||||
std::format("http::context::execute(): curl_multi_remove_handle() returned error {}", (int)cres)));
|
||||
}
|
||||
curl_easy_cleanup(eh);
|
||||
transfers_left -= 1;
|
||||
|
|
@ -190,13 +190,15 @@ namespace gdpm::http{
|
|||
if(transfers_left){
|
||||
cres = curl_multi_wait(cm, NULL, 0, params.timeout, NULL);
|
||||
if(cres != CURLM_OK){
|
||||
log::error("http::context::execute(): curl_multi_wait() returned an error {}", cres);
|
||||
log::error(error(ec::LIBCURL_ERR,
|
||||
std::format("http::context::execute(): curl_multi_wait() returned an error {}", (int)cres)));
|
||||
}
|
||||
}
|
||||
}while(transfers_left);
|
||||
cres = curl_multi_cleanup(cm);
|
||||
if(cres != CURLM_OK){
|
||||
log::error("http::context::execute(): curl_multi_cleanup() returned an error {}", cres);
|
||||
log::error(error(ec::LIBCURL_ERR,
|
||||
std::format("http::context::execute(): curl_multi_cleanup() returned an error {}", (int)cres)));
|
||||
}
|
||||
return responses();
|
||||
}
|
||||
|
|
@ -233,9 +235,7 @@ namespace gdpm::http{
|
|||
/* Get response code, process error, save data, and close file. */
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &r.code);
|
||||
if(res != CURLE_OK && params.verbose > 0){
|
||||
log::error(ec::LIBCURL_ERR,
|
||||
std::format("http::context::download_file::curl_easy_perform() failed: {}", curl_easy_strerror(res))
|
||||
);
|
||||
log::error("http::context::download_file::curl_easy_perform() failed: {}", curl_easy_strerror(res));
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
|
@ -285,9 +285,7 @@ namespace gdpm::http{
|
|||
cres = curl_multi_add_handle(cm, curl);
|
||||
curl_slist_free_all(list);
|
||||
if(cres != CURLM_OK){
|
||||
log::error(ec::LIBCURL_ERR,
|
||||
std::format("http::context::make_downloads(): {}", curl_multi_strerror(cres))
|
||||
);
|
||||
log::error("http::context::make_downstd::format(loads(): {}", curl_multi_strerror(cres));
|
||||
}
|
||||
}
|
||||
transfers_index += 1;
|
||||
|
|
@ -329,7 +327,7 @@ namespace gdpm::http{
|
|||
}
|
||||
cres = curl_multi_remove_handle(cm, eh);
|
||||
if(cres != CURLM_OK){
|
||||
log::error("http::context::execute(): curl_multi_remove_handle() returned error {}", cres);
|
||||
log::error("http::context::execute(): curl_multi_remove_handle() returned error {}", (int)cres);
|
||||
}
|
||||
transfers_left -= 1;
|
||||
curl_easy_cleanup(eh);
|
||||
|
|
@ -348,13 +346,13 @@ namespace gdpm::http{
|
|||
if(transfers_left){
|
||||
cres = curl_multi_wait(cm, NULL, 0, params.timeout, NULL);
|
||||
if(cres != CURLM_OK){
|
||||
log::error("http::context::execute(): curl_multi_wait() returned an error {}", cres);
|
||||
log::error("http::context::execute(): curl_multi_wait() returned an error {}", (int)cres);
|
||||
}
|
||||
}
|
||||
}while(transfers_left);
|
||||
cres = curl_multi_cleanup(cm);
|
||||
if(cres != CURLM_OK){
|
||||
log::error("http::context::execute(): curl_multi_cleanup() returned an error {}", cres);
|
||||
log::error("http::context::execute(): curl_multi_cleanup() returned an error {}", (int)cres);
|
||||
}
|
||||
return responses();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ namespace gdpm::package{
|
|||
error error = cache::update_package_info(p_cache);
|
||||
if(error.has_occurred()){
|
||||
string prefix = std::format(log::get_error_prefix(), utils::timestamp());
|
||||
log::println(GDPM_COLOR_LOG_ERROR"\n{}{}" GDPM_COLOR_RESET, prefix, error.get_message());
|
||||
log::println("\n{}{}{}{}", GDPM_COLOR_LOG_ERROR, prefix, error.get_message(), GDPM_COLOR_RESET);
|
||||
return error;
|
||||
}
|
||||
if(config.clean_temporary){
|
||||
|
|
@ -287,8 +287,7 @@ namespace gdpm::package{
|
|||
if(is_missing_data){
|
||||
doc = rest_api::get_asset(url, p.asset_id, rest_api_params);
|
||||
if(doc.HasParseError() || doc.IsNull()){
|
||||
return log::error_rc(error(
|
||||
constants::error::JSON_ERR,
|
||||
return log::error_rc(error(ec::JSON_ERR,
|
||||
std::format("Error parsing JSON: {}", GetParseError_En(doc.GetParseError()))
|
||||
));
|
||||
}
|
||||
|
|
@ -344,8 +343,7 @@ namespace gdpm::package{
|
|||
if(response.code == http::OK){
|
||||
log::println("Done.");
|
||||
}else{
|
||||
return log::error_rc(error(
|
||||
constants::error::HTTP_RESPONSE_ERR,
|
||||
return log::error_rc(error(ec::HTTP_RESPONSE_ERR,
|
||||
std::format("HTTP Error: {}", response.code)
|
||||
));
|
||||
}
|
||||
|
|
@ -710,8 +708,7 @@ namespace gdpm::package{
|
|||
using namespace std::filesystem;
|
||||
|
||||
if(params.paths.empty()){
|
||||
return log::error_rc(error(
|
||||
constants::error::MALFORMED_PATH,
|
||||
return log::error_rc(error(ec::MALFORMED_PATH,
|
||||
"Path is required"
|
||||
));
|
||||
}
|
||||
|
|
@ -721,8 +718,7 @@ namespace gdpm::package{
|
|||
info_list p_found = {};
|
||||
info_list p_cache = r_cache.unwrap_unsafe();
|
||||
if(p_cache.empty()){
|
||||
return log::error_rc(error(
|
||||
constants::error::NOT_FOUND,
|
||||
return log::error_rc(error(ec::NOT_FOUND,
|
||||
"Could not find any packages to link in cache."
|
||||
));
|
||||
}
|
||||
|
|
@ -735,8 +731,7 @@ namespace gdpm::package{
|
|||
}
|
||||
|
||||
if(p_found.empty()){
|
||||
return log::error_rc(error(
|
||||
constants::error::NO_PACKAGE_FOUND,
|
||||
return log::error_rc(error(ec::NO_PACKAGE_FOUND,
|
||||
"No packages found to link."
|
||||
));
|
||||
}
|
||||
|
|
@ -755,7 +750,7 @@ namespace gdpm::package{
|
|||
std::filesystem::create_directory_symlink(target, symlink_path, ec);
|
||||
if(ec){
|
||||
log::error(error(
|
||||
constants::error::STD_ERR,
|
||||
ec::STD_ERR,
|
||||
std::format("Could not create symlink: {}", ec.message())
|
||||
));
|
||||
}
|
||||
|
|
@ -774,8 +769,7 @@ namespace gdpm::package{
|
|||
|
||||
if(params.paths.empty()){
|
||||
return log::error_rc(error(
|
||||
constants::error::MALFORMED_PATH,
|
||||
"Path is required"
|
||||
ec::MALFORMED_PATH, "Path is required"
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -785,8 +779,7 @@ namespace gdpm::package{
|
|||
|
||||
/* Check for installed packages to clone */
|
||||
if(p_cache.empty()){
|
||||
return log::error_rc(error(
|
||||
constants::error::NO_PACKAGE_FOUND,
|
||||
return log::error_rc(error(ec::NO_PACKAGE_FOUND,
|
||||
"Could not find any packages to clone in cache."
|
||||
));
|
||||
}
|
||||
|
|
@ -804,8 +797,7 @@ namespace gdpm::package{
|
|||
}
|
||||
|
||||
if(p_found.empty()){
|
||||
return log::error_rc(error(
|
||||
constants::error::NO_PACKAGE_FOUND,
|
||||
return log::error_rc(error(ec::NO_PACKAGE_FOUND,
|
||||
"No packages found to clone."
|
||||
));
|
||||
}
|
||||
|
|
@ -913,20 +905,18 @@ namespace gdpm::package{
|
|||
void print_list(const info_list& packages){
|
||||
for(const auto& p : packages){
|
||||
log::println(
|
||||
GDPM_COLOR_BLUE"{}/"
|
||||
GDPM_COLOR_RESET "{}/{}/{} "
|
||||
GDPM_COLOR_GREEN "v{} "
|
||||
GDPM_COLOR_CYAN "{} "
|
||||
GDPM_COLOR_RESET "Godot {}, {}",
|
||||
p.support_level,
|
||||
p.category,
|
||||
"{}{}/{}/{}/{} {}\n\tv{} {} Godot {} {}{}",
|
||||
GDPM_COLOR_GREEN, p.support_level,
|
||||
p.category,
|
||||
p.author,
|
||||
p.title,
|
||||
GDPM_COLOR_CYAN,
|
||||
p.version,
|
||||
p.modify_date,
|
||||
// p.asset_id,
|
||||
p.godot_version,
|
||||
p.cost
|
||||
p.cost,
|
||||
GDPM_COLOR_RESET
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -935,21 +925,18 @@ namespace gdpm::package{
|
|||
void print_list(const rapidjson::Document& json){
|
||||
for(const auto& o : json["result"].GetArray()){
|
||||
log::println(
|
||||
GDPM_COLOR_BLUE"{}/"
|
||||
GDPM_COLOR_CYAN "{}/"
|
||||
GDPM_COLOR_RESET "{}/{} "
|
||||
GDPM_COLOR_GREEN "v{} "
|
||||
GDPM_COLOR_CYAN "{} "
|
||||
GDPM_COLOR_RESET "Godot {}, {}",
|
||||
o["support_level"] .GetString(),
|
||||
"{}{}/{}/{}/{} {}\n\tv{} {} Godot {} {}{}",
|
||||
GDPM_COLOR_GREEN, o["support_level"].GetString(),
|
||||
utils::to_lower(o["category"].GetString()),
|
||||
o["author"] .GetString(),
|
||||
o["title"] .GetString(),
|
||||
o["version_string"] .GetString(),
|
||||
o["modify_date"] .GetString(),
|
||||
// o["asset_id"] .GetString(),
|
||||
o["godot_version"] .GetString(),
|
||||
o["cost"] .GetString()
|
||||
o["author"].GetString(),
|
||||
o["title"].GetString(),
|
||||
GDPM_COLOR_CYAN,
|
||||
o["version_string"].GetString(),
|
||||
o["modify_date"].GetString(),
|
||||
// o["asset_id"].GetString(),
|
||||
o["godot_version"].GetString(),
|
||||
o["cost"].GetString(),
|
||||
GDPM_COLOR_RESET
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,7 @@ namespace gdpm::remote{
|
|||
/* Check if enough args were provided. */
|
||||
log::println("arg count: {}\nargs: {}", args.size(), utils::join(args));
|
||||
if (args.size() < 2){
|
||||
return error(
|
||||
constants::error::INVALID_ARG_COUNT,
|
||||
return error(ec::INVALID_ARG_COUNT,
|
||||
"Requires a remote name and url argument"
|
||||
);
|
||||
}
|
||||
|
|
@ -35,8 +34,7 @@ namespace gdpm::remote{
|
|||
){
|
||||
log::println("arg count: {}\nargs: {}", args.size(), utils::join(args));
|
||||
if(args.size() < 1){
|
||||
return error(
|
||||
constants::error::INVALID_ARG_COUNT,
|
||||
return error(ec::INVALID_ARG_COUNT,
|
||||
"Requires at least one remote name argument"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -242,9 +242,8 @@ namespace gdpm::rest_api{
|
|||
const string_list& filters
|
||||
){
|
||||
if(urls.size() == asset_ids.size() && urls.size() == filters.size()){
|
||||
log::error(ec::ASSERTION_FAILED,
|
||||
"multi::get_assets(): urls.size() != filters.size()"
|
||||
);
|
||||
log::error(error(ec::ASSERTION_FAILED,
|
||||
"multi::get_assets(): urls.size() != filters.size()"));
|
||||
}
|
||||
http::context http(4);
|
||||
http::request params;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue