From f8a7f119bb7c1ffcbefab7fa318b8270b8b42f40 Mon Sep 17 00:00:00 2001 From: celestialorb Date: Thu, 14 Sep 2023 11:25:07 -0700 Subject: [PATCH] raising 404 for outer logic control --- bazelisk.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bazelisk.py b/bazelisk.py index a6af8427..3b45863d 100755 --- a/bazelisk.py +++ b/bazelisk.py @@ -371,16 +371,18 @@ def download(url, destination_path, retries=5, wait_seconds=5): for _ in range(retries): try: sys.stderr.write("Downloading {}...\n".format(url)) + response = None try: response = urlopen(request) with open(destination_path, "wb") as file: shutil.copyfileobj(response, file) return - except HTTPError as exception: - if exception.code == 404: - raise finally: - response.close() + if response: + response.close() + except HTTPError as ex: + if ex.code == 404: + raise except Exception as ex: print("failed to download Bazel resource: {}".format(ex)) finally: