west: blobs: fetch exit immediately on HTTP error
If an HTTP error occurs during `west blobs fetch`, the response was written to a file (even if the response body is empty), and then the checksum validation fails, which can be somewhat confusing. Add an immediate error message and exit-with-error-code when the HTTP request fails. Tested by modify a blob manifest to have an invalid URL: ```bash # test with invalid URL ❯ west blobs fetch nrf_wifi Fetching blob nrf_wifi: .../wifi_fw_bins/default/nrf70.bin ERROR: HTTP error occurred: 404 Client Error: Not Found for url: ... # test with networking disabled ❯ west blobs fetch nrf_wifi Fetching blob nrf_wifi: .../wifi_fw_bins/default/nrf70.bin ERROR: An error occurred: HTTPSConnectionPool(host='git.... \ Max retries exceeded with url: \ .../zzzz/nrf_wifi/bin/zephyr/default/nrf70.bin ... ``` Signed-off-by: Noah Pendleton <noah.pendleton@gmail.com>
This commit is contained in:
parent
a95f900bfa
commit
7f1a639327
1 changed files with 13 additions and 2 deletions
|
@ -2,7 +2,9 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import os
|
||||||
import requests
|
import requests
|
||||||
|
import sys
|
||||||
|
|
||||||
from west import log
|
from west import log
|
||||||
|
|
||||||
|
@ -16,5 +18,14 @@ class HTTPFetcher(ZephyrBlobFetcher):
|
||||||
|
|
||||||
def fetch(self, url, path):
|
def fetch(self, url, path):
|
||||||
log.dbg(f'HTTPFetcher fetching {url} to {path}')
|
log.dbg(f'HTTPFetcher fetching {url} to {path}')
|
||||||
resp = requests.get(url)
|
try:
|
||||||
open(path, "wb").write(resp.content)
|
resp = requests.get(url)
|
||||||
|
resp.raise_for_status() # Raises an HTTPError for bad status codes (4xx or 5xx)
|
||||||
|
except requests.exceptions.HTTPError as e:
|
||||||
|
log.err(f'HTTP error occurred: {e}')
|
||||||
|
sys.exit(os.EX_NOHOST)
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
log.err(f'An error occurred: {e}')
|
||||||
|
sys.exit(os.EX_DATAERR)
|
||||||
|
with open(path, "wb") as f:
|
||||||
|
f.write(resp.content)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue