Skip to content

Commit

Permalink
validation: Confirm yaml file contents are an object (instructlab#1084)
Browse files Browse the repository at this point in the history
The top-level element of a yaml document can be an object (key-value
pairs) or a list. We now test and provide an error message if the
top-level element is not an object.

See instructlab/instructlab#1170

Signed-off-by: BJ Hargrave <[email protected]>
  • Loading branch information
bjhargrave authored and jjasghar committed Jun 10, 2024
1 parent 0c8a55e commit 7334978
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .github/scripts/check-yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from functools import cache, partial
from importlib.resources.abc import Traversable
from pathlib import Path
from typing import List, Optional, Union
from typing import List, Mapping, Optional, Union

# Third Party
import yaml
Expand Down Expand Up @@ -155,6 +155,12 @@ def check(self) -> int:
if not parsed:
self.error(file=taxonomy_path, message="The file is empty")
continue
if not isinstance(parsed, Mapping):
self.error(
file=taxonomy_path,
message="The file is not valid. The top-level element is not an object with key-value pairs.",
)
continue

version = parsed.get("version", 1)
if not isinstance(version, int):
Expand Down

0 comments on commit 7334978

Please sign in to comment.