Skip to content

Commit

Permalink
[util] Add download error handler for missing URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisCummins committed May 25, 2021
1 parent 13990a3 commit 29f6000
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler_gym/util/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def _do_download_attempt(url: str, sha256: Optional[str]) -> bytes:


def _download(urls: List[str], sha256: Optional[str], max_retries: int) -> bytes:
if not urls:
raise ValueError("No URLs to download")

# Cache hit.
if sha256 and cache_path(f"downloads/{sha256}").is_file():
with open(str(cache_path(f"downloads/{sha256}")), "rb") as f:
Expand Down
5 changes: 5 additions & 0 deletions tests/util/download_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,10 @@ def patched_download(*args):
download.download("example", sha256="123")


def test_download_no_urls():
with pytest.raises(ValueError, match="No URLs to download"):
download.download(urls=[])


if __name__ == "__main__":
main()

0 comments on commit 29f6000

Please sign in to comment.