sources/files: don't spam stderr with error messages

Silence the errors, but include instead the error code in the returned
error message.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2020-06-06 15:18:29 +02:00
parent d8e0469516
commit cf8216aea9

View file

@ -94,6 +94,7 @@ def fetch(url, checksum, directory):
# some mirrors are sometimes broken. retry manually, because we could be # some mirrors are sometimes broken. retry manually, because we could be
# redirected to a different, working, one on retry. # redirected to a different, working, one on retry.
start_time = time.monotonic() start_time = time.monotonic()
return_code = 0
for _ in range(20): for _ in range(20):
elapsed_time = time.monotonic() - start_time elapsed_time = time.monotonic() - start_time
if elapsed_time >= 300: if elapsed_time >= 300:
@ -103,7 +104,6 @@ def fetch(url, checksum, directory):
"--silent", "--silent",
"--max-time", f"{300 - elapsed_time}", "--max-time", f"{300 - elapsed_time}",
"--connect-timeout", "60", "--connect-timeout", "60",
"--show-error",
"--fail", "--fail",
"--location", "--location",
"--output", checksum, "--output", checksum,
@ -119,10 +119,11 @@ def fetch(url, checksum, directory):
curl_command.append(url_path) curl_command.append(url_path)
curl = subprocess.run(curl_command, encoding="utf-8", cwd=tmpdir, check=False) curl = subprocess.run(curl_command, encoding="utf-8", cwd=tmpdir, check=False)
if curl.returncode == 0: return_code = curl.returncode
if return_code == 0:
break break
else: else:
raise RuntimeError(f"error downloading {url}") raise RuntimeError(f"curl: error downloading {url}: error code {return_code}")
if not verify_checksum(f"{tmpdir}/{checksum}", checksum): if not verify_checksum(f"{tmpdir}/{checksum}", checksum):
raise RuntimeError(f"checksum mismatch: {checksum} {url}") raise RuntimeError(f"checksum mismatch: {checksum} {url}")