Skip to content

Commit

Permalink
Show reason for Multi-download failure (#1652)
Browse files Browse the repository at this point in the history
Co-authored-by: syslaila <[email protected]>
  • Loading branch information
crogoz authored May 10, 2022
1 parent 6cb7215 commit 070b6e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions libmamba/include/mamba/core/fetch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace mamba

void set_result(CURLcode r);
bool finalize();
std::string get_transfer_msg();

bool can_retry();
CURL* retry();
Expand All @@ -88,6 +89,7 @@ namespace mamba
CURLcode result;
bool failed = false;
int http_status = 10000;
char* effective_url = nullptr;
curl_off_t downloaded_size = 0;
curl_off_t avg_speed = 0;
std::string final_url;
Expand Down
16 changes: 11 additions & 5 deletions libmamba/src/core/fetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,15 +643,12 @@ namespace mamba

bool DownloadTarget::finalize()
{
char* effective_url = nullptr;

avg_speed = get_speed();
curl_easy_getinfo(m_handle, CURLINFO_RESPONSE_CODE, &http_status);
curl_easy_getinfo(m_handle, CURLINFO_EFFECTIVE_URL, &effective_url);
curl_easy_getinfo(m_handle, CURLINFO_SIZE_DOWNLOAD_T, &downloaded_size);

LOG_INFO << "Transfer finalized, status " << http_status << " [" << effective_url << "] "
<< downloaded_size << " bytes";
LOG_INFO << get_transfer_msg();

if (can_retry())
{
Expand Down Expand Up @@ -719,6 +716,14 @@ namespace mamba
return ret;
}

std::string DownloadTarget::get_transfer_msg()
{
std::stringstream ss;
ss << "Transfer finalized, status: " << http_status << " [" << effective_url << "] "
<< downloaded_size << " bytes";
return ss.str();
}

/**************************************
* MultiDownloadTarget implementation *
**************************************/
Expand Down Expand Up @@ -803,7 +808,8 @@ namespace mamba
{
if (failfast && current_target->ignore_failure() == false)
{
throw std::runtime_error("Multi-download failed.");
throw std::runtime_error("Multi-download failed. Reason: "
+ current_target->get_transfer_msg());
}
}
}
Expand Down

0 comments on commit 070b6e3

Please sign in to comment.