From 7d4912bcf9028db491fe1061d3efcf2392c4bd76 Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Sun, 9 Feb 2025 13:41:05 -0800 Subject: [PATCH] filetransfer: report errbuf for failing http codes This was annoying in the case of https://git.lix.systems/lix-project/lix/issues/662 and it's just an oversight. Change-Id: I5af8494dff4621ae2525c28a2c318304545ed665 --- lix/libstore/filetransfer.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lix/libstore/filetransfer.cc b/lix/libstore/filetransfer.cc index d15550b0b..f8c97086a 100644 --- a/lix/libstore/filetransfer.cc +++ b/lix/libstore/filetransfer.cc @@ -397,6 +397,14 @@ struct curlFileTransfer : public FileTransfer std::optional response; if (!successfulStatuses.count(httpStatus)) response = std::move(downloadState.lock()->data); + + auto textualError = [](const char * errbuf, CURLcode code) -> const char * { + if (errbuf && errbuf[0]) { + return errbuf; + } else { + return curl_easy_strerror(code); + } + }; auto exc = code == CURLE_ABORTED_BY_CALLBACK && _isInterrupted ? FileTransferError(Interrupted, std::move(response), "%s of '%s' was interrupted", verb(), uri) @@ -405,11 +413,11 @@ struct curlFileTransfer : public FileTransfer std::move(response), "unable to %s '%s': HTTP error %d (%s)%s", verb(), uri, httpStatus, statusMsg, - code == CURLE_OK ? "" : fmt(" (curl error: %s)", curl_easy_strerror(code))) + code == CURLE_OK ? "" : fmt(" (curl error code=%d: %s)", code, textualError(errbuf, code))) : FileTransferError(err, std::move(response), - "unable to %s '%s': %s (%d) %s", - verb(), uri, curl_easy_strerror(code), code, errbuf); + "unable to %s '%s': %s (curl error code=%d)", + verb(), uri, textualError(errbuf, code), code); fail(std::move(exc)); }