From afcaeb32f6fc8247084df790429a00038e708809 Mon Sep 17 00:00:00 2001 From: Maschell Date: Wed, 18 Jan 2023 21:33:19 +0100 Subject: [PATCH] Improve logging on error --- source/UpdateStateDownloadFiles.cpp | 4 ++-- source/UpdaterStateCheckVersions.cpp | 9 +++++++-- source/utils/FSUtils.cpp | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/source/UpdateStateDownloadFiles.cpp b/source/UpdateStateDownloadFiles.cpp index 1ea1208..9bb1344 100644 --- a/source/UpdateStateDownloadFiles.cpp +++ b/source/UpdateStateDownloadFiles.cpp @@ -31,7 +31,7 @@ int DownloadFilesThreadEntry(UpdaterState *updater) { int errorCode; std::string errorText; if (DownloadUtils::DownloadFileToBuffer(curURL, downloadedZIP, responseCode, errorCode, errorText, &updater->mProgress) < 0 || responseCode != 200) { - DEBUG_FUNCTION_LINE_ERR("Download failed"); + DEBUG_FUNCTION_LINE_ERR("Download failed for %s. curl error code %d, error text %s, response code: %d", curURL.c_str(), errorCode, errorText.c_str(), responseCode); { std::lock_guard lockInfo(updater->mDownloadInfosLock); updater->mDownloadInfos->state = DownloadInfos::DOWNLOAD_FAILED; @@ -89,7 +89,7 @@ int DownloadFilesThreadEntry(UpdaterState *updater) { } if (!found) { - DEBUG_FUNCTION_LINE_ERR("Failed to find file in zip"); + DEBUG_FUNCTION_LINE_ERR("Failed to find with hash %s in zip (%s)", curFile.getSha1().c_str(), curURL.c_str()); { std::lock_guard lockInfo(updater->mDownloadInfosLock); updater->mDownloadInfos->state = DownloadInfos::DOWNLOAD_NOT_FOUND_IN_ZIP; diff --git a/source/UpdaterStateCheckVersions.cpp b/source/UpdaterStateCheckVersions.cpp index ab069e0..818c1fd 100644 --- a/source/UpdaterStateCheckVersions.cpp +++ b/source/UpdaterStateCheckVersions.cpp @@ -10,14 +10,19 @@ int DownloadVersionInfoThreadEntry(UpdaterState *updater) { std::lock_guard lock(updater->mVersionBufferLock); updater->mProgress = 0.0f; - if (DownloadUtils::DownloadFileToBuffer(UPDATE_SERVER_URL "/api/check_versions", + std::string url = UPDATE_SERVER_URL "/api/check_versions"; + if (DownloadUtils::DownloadFileToBuffer(url, updater->mVersionBuffer, updater->mResponseCode, updater->mDownloadErrorCode, updater->mDownloadErrorText, &updater->mProgress) < 0 || updater->mResponseCode != 200) { - DEBUG_FUNCTION_LINE_ERR("Error while downloading"); + DEBUG_FUNCTION_LINE_ERR("Error while downloading \"%s\".", url.c_str()); + DEBUG_FUNCTION_LINE_ERR("curl error code: %d, curl error text %s, response code: %d", + updater->mDownloadErrorCode, + updater->mDownloadErrorText.c_str(), + updater->mResponseCode); updater->mDownloadInfoResult = UpdaterState::DOWNLOAD_FAILED; } else { updater->mDownloadInfoResult = UpdaterState::DOWNLOAD_SUCCESS; diff --git a/source/utils/FSUtils.cpp b/source/utils/FSUtils.cpp index 64b9aae..0362651 100644 --- a/source/utils/FSUtils.cpp +++ b/source/utils/FSUtils.cpp @@ -139,7 +139,7 @@ int32_t CreateSubfolder(const char *fullpath) { int32_t saveBufferToFile(const char *path, void *buffer, uint32_t size) { int fd = open(path, O_CREAT | O_TRUNC | O_WRONLY); if (fd < 0) { - DEBUG_FUNCTION_LINE_ERR("Failed to open %s", path); + DEBUG_FUNCTION_LINE_ERR("Failed to open %s. %d", path, fd); return -1; } auto sizeToWrite = size;