From 9889fa4791b9f300203a41e276288a68db2dea8f Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Tue, 17 Dec 2024 15:45:06 +0000 Subject: [PATCH] Fail earlier if archive download failed Simplify debugging this traceback (which was just an intermittent network error): https://github.com/galaxyproject/galaxy/actions/runs/12374234876/job/34536295999 ``` ______________________ ERROR at setup of test_build_index ______________________ cls = , name = None, mode = 'r' fileobj = , compresslevel = 9, kwargs = {} GzipFile = @classmethod def gzopen(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs): """Open gzip compressed tar archive name for reading or writing. Appending is not allowed. """ if mode not in ("r", "w", "x"): raise ValueError("mode must be 'r', 'w' or 'x'") try: from gzip import GzipFile except ImportError: raise CompressionError("gzip module is not available") try: fileobj = GzipFile(name, mode + "b", compresslevel, fileobj) except OSError: if fileobj is not None and mode == 'r': raise ReadError("not a gzip file") raise try: > t = cls.taropen(name, mode, fileobj, **kwargs) /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/tarfile.py:1854: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/tarfile.py:1831: in taropen return cls(name, mode, fileobj, **kwargs) /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/tarfile.py:1694: in __init__ self.firstmember = self.next() /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/tarfile.py:2578: in next tarinfo = self.tarinfo.fromtarfile(self) /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/tarfile.py:1282: in fromtarfile buf = tarfile.fileobj.read(BLOCKSIZE) /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/gzip.py:292: in read return self._buffer.read(size) /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/_compression.py:68: in readinto data = self.read(len(byte_view)) /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/gzip.py:479: in read if not self._read_gzip_header(): _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def _read_gzip_header(self): magic = self._fp.read(2) if magic == b'': return False if magic != b'\037\213': > raise BadGzipFile('Not a gzipped file (%r)' % magic) E gzip.BadGzipFile: Not a gzipped file (b' tarfile.open(fileobj=b, mode="r:gz").extractall(extracted_archive_dir) test/unit/tool_shed/test_shed_index.py:30: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/tarfile.py:1801: in open return func(name, filemode, fileobj, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ cls = , name = None, mode = 'r' fileobj = , compresslevel = 9, kwargs = {} GzipFile = @classmethod def gzopen(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs): """Open gzip compressed tar archive name for reading or writing. Appending is not allowed. """ if mode not in ("r", "w", "x"): raise ValueError("mode must be 'r', 'w' or 'x'") try: from gzip import GzipFile except ImportError: raise CompressionError("gzip module is not available") try: fileobj = GzipFile(name, mode + "b", compresslevel, fileobj) except OSError: if fileobj is not None and mode == 'r': raise ReadError("not a gzip file") raise try: t = cls.taropen(name, mode, fileobj, **kwargs) except OSError: fileobj.close() if mode == 'r': > raise ReadError("not a gzip file") E tarfile.ReadError: not a gzip file /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/tarfile.py:1858: ReadError ------------------------------ Captured log setup ------------------------------ DEBUG urllib3.connectionpool:connectionpool.py:1022 Starting new HTTPS connection (1): github.com:443 DEBUG urllib3.connectionpool:connectionpool.py:475 https://github.com:443 "GET /mvdbeek/toolshed-test-data/blob/master/toolshed_community_files.tgz?raw=true HTTP/1.1" 503 54894 ``` --- test/unit/tool_shed/test_shed_index.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unit/tool_shed/test_shed_index.py b/test/unit/tool_shed/test_shed_index.py index bc929dcddfb1..880489151e2d 100644 --- a/test/unit/tool_shed/test_shed_index.py +++ b/test/unit/tool_shed/test_shed_index.py @@ -26,7 +26,9 @@ def whoosh_index_dir(): @pytest.fixture(scope="module") def community_file_dir(): extracted_archive_dir = tempfile.mkdtemp() - b = BytesIO(requests.get(URL).content) + response = requests.get(URL) + response.raise_for_status() + b = BytesIO(response.content) tarfile.open(fileobj=b, mode="r:gz").extractall(extracted_archive_dir) try: yield extracted_archive_dir