Skip to content

Commit

Permalink
Catch malformed JSON files
Browse files Browse the repository at this point in the history
  • Loading branch information
layday committed Nov 8, 2022
1 parent bc77bec commit a8caef9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ async def extract_project_ids_from_toc_files(get: Get, url: str):
for t in tocs
)
project_ids = (next(filter(None, s), None) for s in zip(*toc_ids))
logger.debug(f"extracted {project_ids}")

else:
project_ids = (None,) * 3
Expand Down Expand Up @@ -287,13 +286,19 @@ async def parse_repo(get: Get, repo: Mapping[str, Any]):
async with get(
maybe_release_json_asset["browser_download_url"]
) as release_json_response:
release_json_contents = await release_json_response.json(content_type=None)
try:
release_json_contents = await release_json_response.json(content_type=None)
except json.JSONDecodeError:
logger.exception(
f"release.json is not valid JSON: {maybe_release_json_asset['browser_download_url']}"
)
return

try:
release_json = ReleaseJson.from_dict(release_json_contents)
except BaseValidationError:
logger.exception(
f"release.json is malformed: {maybe_release_json_asset['browser_download_url']}"
f"release.json has incorrect schema: {maybe_release_json_asset['browser_download_url']}"
)
return

Expand Down

0 comments on commit a8caef9

Please sign in to comment.