Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

484 error handeling in case of empty yaml block #1024

Merged
merged 7 commits into from
Aug 28, 2023
12 changes: 12 additions & 0 deletions src/esm_parser/esm_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,23 @@ def initialize_from_yaml(filepath):
)
return user_config

def check_for_empty_components_in_user_config(user_config):
for model in list(user_config):
if user_config[model] is None or user_config[model] == "" or not user_config[model]:
user_note(
f"Warning: YAML syntax",
f"The component ``{model}`` in your configuration "
f"file ``{user_config['general']['runscript_abspath']}`` is empty. "
"No further variables are set for this component in your runscript."
)
del user_config[model]
return user_config

def complete_config(user_config):
if not "general" in user_config:
user_config["general"] = {}
user_config["general"]["additional_files"] = []
user_config = check_for_empty_components_in_user_config(user_config)

while True:
for model in list(user_config):
Expand Down
2 changes: 0 additions & 2 deletions src/esm_parser/yaml_to_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ def yaml_file_to_dict(filepath):
yaml_load["computer"]["runtime_environment_changes"][
"add_export_vars"
] = add_export_vars
# Check for empty components/models
# check_for_empty_components(yaml_load, filepath + extension)
return yaml_load
except IOError as error:
logger.debug(
Expand Down
5 changes: 4 additions & 1 deletion src/esm_runscripts/config_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ def get_user_config_from_command_line(command_line_config):
except SystemExit as sysexit:
sys.exit(sysexit)
except:
raise("An error occurred reading the config file from the command line")
esm_parser.user_error(
"Syntax error",
f"An error occurred while reading the config file "
f"``{command_line_config['runscript_abspath']}`` from the command line.")

# NOTE(PG): I really really don't like this. But I also don't want to
# re-introduce black/white lists
Expand Down
Loading