Skip to content

Commit 77c0a89

Browse files
committed
testing: litevm: gracefully handle 404
The urllib.HTTPError exception, in addition to printing a quite large stack trace, omits the URL. This is probably a good thing for security, but here we don't care because we're fetching public URLs anyway. So catch the exception, print a formatted error message, and then use sys.exit to avoid a traceback. This way, the CI errors will actually let us know which RPM is missing. I mean, it's always the kernel-ueknext-debuginfo. It's never not that. But still, I want the CI to tell me that rather than forcing me to guess. Signed-off-by: Stephen Brennan <[email protected]>
1 parent 1a07f7f commit 77c0a89

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

testing/litevm/rpm.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
import shutil
1111
import sqlite3
1212
import subprocess
13+
import sys
1314
import xml.etree.ElementTree as ET
1415
from pathlib import Path
1516
from typing import List
1617
from typing import Optional
1718
from typing import Union
19+
from urllib.error import HTTPError
1820

1921
from drgn_tools.util import download_file
2022
from testing.util import BASE_DIR
@@ -210,22 +212,28 @@ def _get_rpms(self) -> None:
210212
self._getlatest()
211213

212214
self._rpm_paths = []
213-
for i, url in enumerate(self._rpm_urls):
215+
try:
216+
for i, url in enumerate(self._rpm_urls):
217+
path = download_file_cached(
218+
url,
219+
desc=f"RPM {i + 1}/{len(self._rpm_urls)}",
220+
cache=self.cache_dir,
221+
cache_key=self._cache_key("rpm"),
222+
delete_on_miss=(i == 0),
223+
)
224+
self._rpm_paths.append(path)
214225
path = download_file_cached(
215-
url,
216-
desc=f"RPM {i + 1}/{len(self._rpm_urls)}",
226+
self._dbinfo_url,
227+
desc="Debuginfo RPM",
217228
cache=self.cache_dir,
218229
cache_key=self._cache_key("rpm"),
219-
delete_on_miss=(i == 0),
230+
delete_on_miss=False,
231+
)
232+
except HTTPError as e:
233+
sys.exit(
234+
f"HTTP error {e.code} {e.reason} encountered while "
235+
f"fetching URL:\n{e.url}"
220236
)
221-
self._rpm_paths.append(path)
222-
path = download_file_cached(
223-
self._dbinfo_url,
224-
desc="Debuginfo RPM",
225-
cache=self.cache_dir,
226-
cache_key=self._cache_key("rpm"),
227-
delete_on_miss=False,
228-
)
229237
self._dbinfo_path = path
230238

231239
def get_rpms(self) -> List[Path]:

0 commit comments

Comments
 (0)