Skip to content

Commit

Permalink
fix(py): ignore JSON files with invalid categories
Browse files Browse the repository at this point in the history
When a category, such as "images" occurs in the JSON file, it was
assumed that it was a dictionary, but that may not be the case, hence it
crashed when trying to access a dict value. This now just ignores them.
  • Loading branch information
jungomi committed Jul 13, 2023
1 parent 42e48ad commit 76b91d0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions py/lavd/fs.py
Expand Up @@ -101,21 +101,24 @@ def insert_file(
abs_path = Path(abs_path)
if file_category == "json":
json_data = load_json(abs_path)
if "scalars" in json_data:
data.set("scalars", name, step, category, json_data["scalars"])
if "texts" in json_data:
text = json_data["texts"]
text_len = len(text.get("actual", "")) + len(text.get("expeted", ""))
scalars_dict = json_data.get("scalars")
if isinstance(scalars_dict, dict):
data.set("scalars", name, step, category, scalars_dict)
text_dict = json_data.get("texts")
if isinstance(text_dict, dict):
text_len = len(text_dict.get("actual", "")) + len(
text_dict.get("expeted", "")
)
data.set(
"texts",
name,
step,
category,
text,
text_dict,
truncate=text_len > MAX_TEXT_LEN,
)
if "images" in json_data:
image_dict = json_data["images"]
image_dict = json_data.get("images")
if isinstance(image_dict, dict):
image_source = image_dict.get("source")
if image_source:
image_path = abs_path.parent / image_source
Expand Down

0 comments on commit 76b91d0

Please sign in to comment.