Downloader: log errors when downloading
If an error is returned from HuggingFace, raise it to the calling function. Signed-off-by: kingbri <8082010+kingbri1@users.noreply.github.com>
This commit is contained in:
parent
48bb78c614
commit
c580893054
2 changed files with 22 additions and 11 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
|
import traceback
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from common.downloader import hf_repo_download
|
from common.downloader import hf_repo_download
|
||||||
|
|
@ -10,6 +11,7 @@ from endpoints.server import export_openapi
|
||||||
|
|
||||||
|
|
||||||
def download_action(args: argparse.Namespace):
|
def download_action(args: argparse.Namespace):
|
||||||
|
try:
|
||||||
asyncio.run(
|
asyncio.run(
|
||||||
hf_repo_download(
|
hf_repo_download(
|
||||||
repo_id=args.repo_id,
|
repo_id=args.repo_id,
|
||||||
|
|
@ -20,6 +22,9 @@ def download_action(args: argparse.Namespace):
|
||||||
exclude=args.exclude,
|
exclude=args.exclude,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
except Exception:
|
||||||
|
exception = traceback.format_exc()
|
||||||
|
logger.error(exception)
|
||||||
|
|
||||||
|
|
||||||
def config_export_action(args: argparse.Namespace):
|
def config_export_action(args: argparse.Namespace):
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,14 @@ async def _download_file(
|
||||||
req_headers = {"Authorization": f"Bearer {token}"} if token else {}
|
req_headers = {"Authorization": f"Bearer {token}"} if token else {}
|
||||||
|
|
||||||
async with session.get(url, headers=req_headers) as response:
|
async with session.get(url, headers=req_headers) as response:
|
||||||
# TODO: Change to raise errors
|
if not response.ok:
|
||||||
assert response.status == 200
|
error_text = await response.text()
|
||||||
|
raise aiohttp.ClientResponseError(
|
||||||
|
response.request_info,
|
||||||
|
response.history,
|
||||||
|
status=response.status,
|
||||||
|
message=f"HTTP {response.status}: {error_text}",
|
||||||
|
)
|
||||||
|
|
||||||
file_size = int(response.headers["Content-Length"])
|
file_size = int(response.headers["Content-Length"])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue