From bb7e52a4a8e4740bd34e51e0be8b65838aba8cfc Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Fri, 15 Nov 2019 14:31:19 +0100 Subject: [PATCH] tools: Produce user friendly error during install when the server is down Closes https://github.com/espressif/esp-idf/issues/4329 --- tools/idf_tools.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/idf_tools.py b/tools/idf_tools.py index aeb4721c27..158b5a7648 100755 --- a/tools/idf_tools.py +++ b/tools/idf_tools.py @@ -565,11 +565,16 @@ class IDFTool(object): for retry in range(DOWNLOAD_RETRY_COUNT): local_temp_path = local_path + '.tmp' info('Downloading {} to {}'.format(archive_name, local_temp_path)) - urlretrieve(url, local_temp_path, report_progress if not global_non_interactive else None) - sys.stdout.write("\rDone\n") + try: + urlretrieve(url, local_temp_path, report_progress if not global_non_interactive else None) + sys.stdout.write("\rDone\n") + except Exception as e: + # urlretrieve could throw different exceptions, e.g. IOError when the server is down + # Errors are ignored because the downloaded file is checked a couple of lines later. + warn('Download failure {}'.format(e)) sys.stdout.flush() - if not self.check_download_file(download_obj, local_temp_path): - warn('Failed to download file {}'.format(local_temp_path)) + if not os.path.isfile(local_temp_path) or not self.check_download_file(download_obj, local_temp_path): + warn('Failed to download {} to {}'.format(url, local_temp_path)) continue rename_with_retry(local_temp_path, local_path) downloaded = True