From 1060e93783e7d0b0d68ecb56c8747366d115d366 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 28 Aug 2021 16:11:53 +0200 Subject: [PATCH] curl: log errors --- rpcs3/main.cpp | 27 +++++++++++++++++++++------ rpcs3/rpcs3qt/curl_handle.cpp | 6 +++++- rpcs3/rpcs3qt/downloader.cpp | 17 ++++++++++++----- rpcs3/rpcs3qt/rsx_debugger.cpp | 2 -- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index 859d0fc2a6..4fa53c7ce2 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -584,16 +584,20 @@ int main(int argc, char** argv) hhdr = curl_slist_append(hhdr, "Accept: application/vnd.github.v3+json"); hhdr = curl_slist_append(hhdr, "User-Agent: curl/7.37.0"); - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, hhdr); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, +[](const char* ptr, usz, usz size, void* json) -> usz + CURLcode err = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, hhdr); + if (err != CURLE_OK) fprintf(stderr, "curl_easy_setopt(CURLOPT_HTTPHEADER) error: %s", curl_easy_strerror(err)); + + err = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, +[](const char* ptr, usz, usz size, void* json) -> usz { static_cast(json)->append(ptr, size); return size; }); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf); + if (err != CURLE_OK) fprintf(stderr, "curl_easy_setopt(CURLOPT_WRITEFUNCTION) error: %s", curl_easy_strerror(err)); + + err = curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf); + if (err != CURLE_OK) fprintf(stderr, "curl_easy_setopt(CURLOPT_WRITEDATA) error: %s", curl_easy_strerror(err)); u32 page = 1; - constexpr u32 per_page = 100; while (page <= 55) @@ -603,8 +607,19 @@ int main(int argc, char** argv) if (!from.empty()) fmt::append(url, "&sha=%s", from); - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - curl_easy_perform(curl); + err = curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); + if (err != CURLE_OK) + { + fprintf(stderr, "curl_easy_setopt(CURLOPT_URL, %s) error: %s", url.c_str(), curl_easy_strerror(err)); + break; + } + + err = curl_easy_perform(curl); + if (err != CURLE_OK) + { + fprintf(stderr, "Curl error:\n%s", curl_easy_strerror(err)); + break; + } QJsonDocument info = QJsonDocument::fromJson(buf); diff --git a/rpcs3/rpcs3qt/curl_handle.cpp b/rpcs3/rpcs3qt/curl_handle.cpp index 2541cd1b6d..55a876e6c0 100644 --- a/rpcs3/rpcs3qt/curl_handle.cpp +++ b/rpcs3/rpcs3qt/curl_handle.cpp @@ -1,10 +1,13 @@ #include "curl_handle.h" #include "Emu/system_utils.hpp" +#include "util/logs.hpp" #ifdef _WIN32 #include "Utilities/StrUtil.h" #endif +LOG_CHANNEL(network_log, "NET"); + curl_handle::curl_handle(QObject* parent) : QObject(parent) { m_curl = curl_easy_init(); @@ -14,7 +17,8 @@ curl_handle::curl_handle(QObject* parent) : QObject(parent) const std::string path_to_cert = rpcs3::utils::get_exe_dir() + "cacert.pem"; const std::string ansi_path = utf8_path_to_ansi_path(path_to_cert); - curl_easy_setopt(m_curl, CURLOPT_CAINFO, ansi_path.data()); + const CURLcode err = curl_easy_setopt(m_curl, CURLOPT_CAINFO, ansi_path.data()); + if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_CAINFO, %s) error: %s", ansi_path, curl_easy_strerror(err)); #endif } diff --git a/rpcs3/rpcs3qt/downloader.cpp b/rpcs3/rpcs3qt/downloader.cpp index e286559a61..9c5bc632af 100644 --- a/rpcs3/rpcs3qt/downloader.cpp +++ b/rpcs3/rpcs3qt/downloader.cpp @@ -8,7 +8,7 @@ #include "Crypto/sha256.h" #include "util/logs.hpp" -LOG_CHANNEL(network_log, "NETWORK"); +LOG_CHANNEL(network_log, "NET"); usz curl_write_cb_compat(char* ptr, usz /*size*/, usz nmemb, void* userdata) { @@ -48,10 +48,17 @@ void downloader::start(const std::string& url, bool follow_location, bool show_p m_curl_buf.clear(); m_curl_abort = false; - curl_easy_setopt(m_curl->get_curl(), CURLOPT_URL, url.c_str()); - curl_easy_setopt(m_curl->get_curl(), CURLOPT_WRITEFUNCTION, curl_write_cb_compat); - curl_easy_setopt(m_curl->get_curl(), CURLOPT_WRITEDATA, this); - curl_easy_setopt(m_curl->get_curl(), CURLOPT_FOLLOWLOCATION, follow_location ? 1 : 0); + CURLcode err = curl_easy_setopt(m_curl->get_curl(), CURLOPT_URL, url.c_str()); + if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_URL, %s) error: %s", url, curl_easy_strerror(err)); + + err = curl_easy_setopt(m_curl->get_curl(), CURLOPT_WRITEFUNCTION, curl_write_cb_compat); + if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_WRITEFUNCTION, curl_write_cb_compat) error: %s", curl_easy_strerror(err)); + + err = curl_easy_setopt(m_curl->get_curl(), CURLOPT_WRITEDATA, this); + if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_WRITEDATA) error: %s", curl_easy_strerror(err)); + + err = curl_easy_setopt(m_curl->get_curl(), CURLOPT_FOLLOWLOCATION, follow_location ? 1 : 0); + if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_FOLLOWLOCATION, %d) error: %s", follow_location, curl_easy_strerror(err)); m_thread = QThread::create([this] { diff --git a/rpcs3/rpcs3qt/rsx_debugger.cpp b/rpcs3/rpcs3qt/rsx_debugger.cpp index 0fe11e4a5a..f946171f90 100644 --- a/rpcs3/rpcs3qt/rsx_debugger.cpp +++ b/rpcs3/rpcs3qt/rsx_debugger.cpp @@ -47,8 +47,6 @@ rsx_debugger::rsx_debugger(std::shared_ptr gui_settings, QWidget* QLabel l("000000000"); // hacky way to get the lineedit to resize properly l.setFont(mono); - QHBoxLayout* hbox_controls_addr = new QHBoxLayout(); - // Controls: Breaks QPushButton* b_break_frame = new QPushButton(tr("Frame")); QPushButton* b_break_text = new QPushButton(tr("Texture"));