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:
kingbri 2025-02-19 23:16:17 -05:00
parent 48bb78c614
commit c580893054
2 changed files with 22 additions and 11 deletions

View file

@ -1,6 +1,7 @@
import argparse
import asyncio
import json
import traceback
from loguru import logger
from common.downloader import hf_repo_download
@ -10,16 +11,20 @@ from endpoints.server import export_openapi
def download_action(args: argparse.Namespace):
asyncio.run(
hf_repo_download(
repo_id=args.repo_id,
folder_name=args.folder_name,
revision=args.revision,
token=args.token,
include=args.include,
exclude=args.exclude,
try:
asyncio.run(
hf_repo_download(
repo_id=args.repo_id,
folder_name=args.folder_name,
revision=args.revision,
token=args.token,
include=args.include,
exclude=args.exclude,
)
)
)
except Exception:
exception = traceback.format_exc()
logger.error(exception)
def config_export_action(args: argparse.Namespace):

View file

@ -37,8 +37,14 @@ async def _download_file(
req_headers = {"Authorization": f"Bearer {token}"} if token else {}
async with session.get(url, headers=req_headers) as response:
# TODO: Change to raise errors
assert response.status == 200
if not response.ok:
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"])