Repository: ESMCI/cime

Issue:
Error message for grid aliases should be more clear about the problem
Two different cases result in the same error message:

(1) Providing a grid alias that doesn't exist at all:

```
[yslogin1:/glade/scratch/sacks/cesm_code/cesm2_0_alpha06i_newCime/cime/scripts]$ ./create_newcase -case test_grid_0421d -compset ICLM45 -res blah_blah
Compset longname is 2000_DATM%QIA_CLM45%SP_SICE_SOCN_RTM_SGLC_SWAV
Compset specification file is /glade2/scratch2/sacks/cesm_code/cesm2_0_alpha06i_newCime/cime/../components/clm/cime_config/config_compsets.xml
Pes     specification file is /glade2/scratch2/sacks/cesm_code/cesm2_0_alpha06i_newCime/cime/../components/clm/cime_config/config_pes.xml
ERROR: ERROR: no alias was found for blah_blah
```

(2) Providing a grid alias that exists, but isn't valid for this compset:

```
[yslogin1:/glade/scratch/sacks/cesm_code/cesm2_0_alpha06i_newCime/cime/scripts]$ ./create_newcase -case test_grid_0421d -compset ICLM45 -res f09_g16_gl4
Compset longname is 2000_DATM%QIA_CLM45%SP_SICE_SOCN_RTM_SGLC_SWAV
Compset specification file is /glade2/scratch2/sacks/cesm_code/cesm2_0_alpha06i_newCime/cime/../components/clm/cime_config/config_compsets.xml
Pes     specification file is /glade2/scratch2/sacks/cesm_code/cesm2_0_alpha06i_newCime/cime/../components/clm/cime_config/config_pes.xml
ERROR: ERROR: no alias was found for f09_g16_gl4
```

The error message should distinguish between these cases: In the second case it should say something like, "Grid alias f09_g16_gl4 is not valid for this compset" (this used to be done in the perl).


Discussion:

Resolving patch:
diff --git a/scripts/lib/CIME/XML/grids.py b/scripts/lib/CIME/XML/grids.py
--- a/scripts/lib/CIME/XML/grids.py
+++ b/scripts/lib/CIME/XML/grids.py
@@ -142,17 +142,19 @@ def _read_config_grids_v2(self, name, compset, atmnlev, lndnlev):
 
         model_gridnodes = self.get_nodes("model_grid")
         model_gridnode = None
+        foundalias = False
         for node in model_gridnodes:
-            found = False
             alias = node.get("alias")
             if alias == name:
+                foundalias = True
+                foundcompset = False
                 compset_attrib = node.get("compset")
                 not_compset_attrib = node.get("not_compset")
                 if compset_attrib and not_compset_attrib:
                     compset_match = re.search(compset_attrib, compset)
                     not_compset_match = re.search(not_compset_attrib, compset)
                     if compset_match is not None and not_compset_match is not None:
-                        found = True
+                        foundcompset = True
                         model_gridnode = node
                         logger.debug("Found match for %s with compset_match %s and not_compset_match %s"
                                      % (alias, compset_attrib, not_compset_attrib))
@@ -160,7 +162,7 @@ def _read_config_grids_v2(self, name, compset, atmnlev, lndnlev):
                 elif compset_attrib:
                     compset_match = re.search(compset_attrib, compset)
                     if compset_match is not None:
-                        found = True
+                        foundcompset = True
                         model_gridnode = node
                         logger.debug("Found match for %s with compset_match %s"
                                      % (alias, compset_attrib))
@@ -168,19 +170,19 @@ def _read_config_grids_v2(self, name, compset, atmnlev, lndnlev):
                 elif not_compset_attrib:
                     not_compset_match = re.search(not_compset_attrib, compset)
                     if not_compset_match is None:
-                        found = True
+                        foundcompset = True
                         model_gridnode = node
                         logger.debug("Found match for %s with not_compset_match %s"
                                      % (alias, not_compset_attrib))
                         break
                 else:
-                    found = True
+                    foundcompset = True
                     model_gridnode = node
                     logger.debug("Found match for %s" %(alias))
                     break
-
+        expect(foundalias, "no alias %s defined" %name)
         # if no match is found in config_grids.xml - exit
-        expect(found, "ERROR: no alias was found for %s " %name)
+        expect(foundcompset, "grid alias %s not valid for compset %s" %(name, compset))
 
         # for the match - find all of the component grid settings
         grid_nodes = self.get_nodes("grid", root=model_gridnode)


Test patch: