elog-gen.py: handle absence of metadata

An error may just want to inherit metadata from another error, without
adding metadata of it's own. In such a case, the metadata file won't
have the "meta" keyword, although it will have the "inherits" keyword.

Accept metadata files that don't have the "meta" keyword.

Change-Id: I4e30e035f19d6af8e0e1f654465d109fe5284a1b
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/tools/elog-gen.py b/tools/elog-gen.py
index 0452489..469248f 100755
--- a/tools/elog-gen.py
+++ b/tools/elog-gen.py
@@ -214,14 +214,15 @@
             error_lvl[fullname] = "INFO"
         tmp_meta = []
         # grab all the meta data fields and info
-        for j in i['meta']:
-            str_short = j['str'].split('=')[0]
-            tmp_meta.append(str_short)
-            meta_data[str_short] = {}
-            meta_data[str_short]['str'] = j['str']
-            meta_data[str_short]['str_short'] = str_short
-            meta_data[str_short]['type'] = get_cpp_type(j['type'])
-        meta[fullname] = tmp_meta
+        if('meta' in i):
+            for j in i['meta']:
+                str_short = j['str'].split('=')[0]
+                tmp_meta.append(str_short)
+                meta_data[str_short] = {}
+                meta_data[str_short]['str'] = j['str']
+                meta_data[str_short]['str_short'] = str_short
+                meta_data[str_short]['type'] = get_cpp_type(j['type'])
+            meta[fullname] = tmp_meta
 
     # Debug
     # for i in errors:
diff --git a/tools/phosphor-logging/templates/elog-gen-template.mako.hpp b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
index 181d4bd..e321e6b 100644
--- a/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
+++ b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
@@ -32,7 +32,13 @@
 {
 namespace _${classname}
 {
-    % for b in meta[name]:
+<%
+    meta_list = []
+    if(name in meta):
+        meta_list = meta[name]
+%>\
+
+    % for b in meta_list:
 struct ${b}
 {
     static constexpr auto str = "${meta_data[b]['str']}";
@@ -45,7 +51,9 @@
 
 }  // namespace _${classname}
 <%
-    meta_string = ', '.join(meta[name])
+    meta_string = ""
+    if(meta_list):
+        meta_string = ', '.join(meta_list)
     parent_meta = []
 
     parent = parents[name]
@@ -58,7 +66,10 @@
         parent_meta += [parent_namespace + "::Error::" + parent_name + "::" +
                         p for p in meta[parent]]
         parent_meta_short = ', '.join(meta[parent])
-        meta_string = meta_string + ", " + parent_meta_short
+        if(meta_string):
+            meta_string = meta_string + ", " + parent_meta_short
+        else:
+            meta_string = parent_meta_short
         parent = parents[parent]
 %>
 struct ${classname}
@@ -66,7 +77,7 @@
     static constexpr auto err_code = "${name}";
     static constexpr auto err_msg = "${error_msg[name]}";
     static constexpr auto L = level::${error_lvl[name]};
-    % for b in meta[name]:
+    % for b in meta_list:
     using ${b} = _${classname}::${b};
     % endfor
     % for b in parent_meta:
diff --git a/tools/phosphor-logging/templates/elog-lookup-template.mako.cpp b/tools/phosphor-logging/templates/elog-lookup-template.mako.cpp
index 822d91d..4f1ce15 100644
--- a/tools/phosphor-logging/templates/elog-lookup-template.mako.cpp
+++ b/tools/phosphor-logging/templates/elog-lookup-template.mako.cpp
@@ -14,14 +14,18 @@
 
 std::map<std::string,std::vector<std::string>> g_errMetaMap = {
     % for a in errors:
-    <% meta_string = '\",\"'.join(meta[a]) %> \
+<%
+    meta_list = []
+    if(a in meta):
+        meta_list = meta[a]
+%>\
+    <% meta_string = '\",\"'.join(meta_list) %> \
     {"${a}",{"${meta_string}"}},
     % endfor
 };
 
 std::map<std::string,level> g_errLevelMap = {
     % for a in errors:
-    <% meta_string = '\",\"'.join(meta[a]) %> \
     {"${a}",level::${error_lvl[a]}},
     % endfor
 };