From 17b3ee6eaf326249c477b20ae976794817efc3ee Mon Sep 17 00:00:00 2001 From: Benjamin S Wolf Date: Sat, 30 Nov 2024 20:18:00 -0800 Subject: [PATCH] Core: warn if a yaml is empty (#4117) * Core: warn if a yaml is empty * WebHost: ignore empty yaml Generate: log which yaml documents are empty * Actually remove empty yamls from weight_cache * More verbose variable name --------- Co-authored-by: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> --- Generate.py | 9 ++++++++- WebHostLib/check.py | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Generate.py b/Generate.py index 8aba72ab..35c39627 100644 --- a/Generate.py +++ b/Generate.py @@ -114,7 +114,14 @@ def main(args=None) -> Tuple[argparse.Namespace, int]: os.path.join(args.player_files_path, fname) not in {args.meta_file_path, args.weights_file_path}: path = os.path.join(args.player_files_path, fname) try: - weights_cache[fname] = read_weights_yamls(path) + weights_for_file = [] + for doc_idx, yaml in enumerate(read_weights_yamls(path)): + if yaml is None: + logging.warning(f"Ignoring empty yaml document #{doc_idx + 1} in {fname}") + else: + weights_for_file.append(yaml) + weights_cache[fname] = tuple(weights_for_file) + except Exception as e: raise ValueError(f"File {fname} is invalid. Please fix your yaml.") from e diff --git a/WebHostLib/check.py b/WebHostLib/check.py index 97cb797f..4e0cf117 100644 --- a/WebHostLib/check.py +++ b/WebHostLib/check.py @@ -105,8 +105,9 @@ def roll_options(options: Dict[str, Union[dict, str]], plando_options=plando_options) else: for i, yaml_data in enumerate(yaml_datas): - rolled_results[f"{filename}/{i + 1}"] = roll_settings(yaml_data, - plando_options=plando_options) + if yaml_data is not None: + rolled_results[f"{filename}/{i + 1}"] = roll_settings(yaml_data, + plando_options=plando_options) except Exception as e: if e.__cause__: results[filename] = f"Failed to generate options in {filename}: {e} - {e.__cause__}"