From 1e403a8574096d58cfb332cd620faaea156359eb Mon Sep 17 00:00:00 2001 From: Sam Rabin Date: Thu, 5 Sep 2024 13:43:43 -0600 Subject: [PATCH] Provide hint in error message if namelist variable invalid due to surrounding quote marks. --- cime_config/stream_cdeps.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/cime_config/stream_cdeps.py b/cime_config/stream_cdeps.py index 1f702a13..5a9b4b82 100644 --- a/cime_config/stream_cdeps.py +++ b/cime_config/stream_cdeps.py @@ -315,14 +315,30 @@ def create_stream_xml( ), ) if var_key in valid_values: + + # # Handle, e.g., 'bilinear' in namelist instead of bilinear (no quotes) + mod_dict_var_key = mod_dict[var_key] + + # Check that key is valid + is_valid = mod_dict_var_key in valid_values[var_key] + msg = "{} can only have values of {} for stream {} in file {}, not {}".format( + var_key, + valid_values[var_key], + stream_name, + user_mods_file, + mod_dict[var_key], + ) + if not is_valid: + # Check for surrounding quote marks + has_surrounding_quotes = ( + (mod_dict_var_key[0] == mod_dict_var_key[-1] == "'") or + (mod_dict_var_key[0] == mod_dict_var_key[-1] == '"') + ) + if has_surrounding_quotes and mod_dict_var_key[1:-1] in valid_values[var_key]: + msg += " (try removing surrounding quotes)" expect( - mod_dict[var_key] in valid_values[var_key], - "{} can only have values of {} for stream {} in file {}".format( - var_key, - valid_values[var_key], - stream_name, - user_mods_file, - ), + is_valid, + msg, ) stream_vars["stream_" + var_key] = mod_dict[var_key] if var_key == "datafiles":