Gracefully handle templates that lack contents in their description or created_with...
authorBen Loftis <ben@harrisonconsoles.com>
Wed, 30 Aug 2017 15:20:29 +0000 (10:20 -0500)
committerBen Loftis <ben@harrisonconsoles.com>
Wed, 30 Aug 2017 15:23:34 +0000 (10:23 -0500)
libs/ardour/template_utils.cc

index 80baf47f54f2b15c5c72b1cd9146248b9c89673d..5c6fd9c833e2fe4614b2138dad73cf7cd5eee470 100644 (file)
@@ -101,26 +101,32 @@ find_session_templates (vector<TemplateInfo>& template_names, bool read_xml)
                rti.path = *i;
 
                if (read_xml) {
+
                        XMLTree tree;
                        if (!tree.read (file.c_str())) {
+                               cerr << "Failed to parse Route-template XML file: " << file;
                                continue;
                        }
 
-                       string created_with = _("(unknown)");
-                       XMLNode *pv = tree.root()->child("ProgramVersion");
-                       if (pv != 0) {
-                               pv->get_property (X_("created-with"), created_with);
-                       }
-
-                       string description = _("No Description");
-                       XMLNode *desc = tree.root()->child("description");
-                       if (desc != 0) {
-                               description = desc->attribute_value();
-                       }
-
-                       rti.created_with = created_with;
-                       rti.description = description;
-
+                       XMLNode* root = tree.root();
+                       
+                       rti.created_with = _("(unknown)");
+                       try {
+                               XMLNode *pv = root->child("ProgramVersion");
+                               string created_with;
+                               if (pv != 0) {
+                                       pv->get_property (X_("created-with"), created_with);
+                               }
+                               rti.created_with = created_with;
+                       } catch ( LIBPBD_API::XMLException &e) {}
+
+                       rti.description = _("No Description");
+                       try {
+                               XMLNode *desc = root->child("description");
+                               if (desc != 0) {
+                                       rti.description = desc->attribute_value();
+                               }
+                       } catch ( LIBPBD_API::XMLException &e) {}
                }
 
                template_names.push_back (rti);
@@ -144,22 +150,34 @@ find_route_templates (vector<TemplateInfo>& template_names)
                XMLTree tree;
 
                if (!tree.read (fullpath.c_str())) {
+                       cerr << "Failed to parse Route-template XML file: " << fullpath;
                        continue;
                }
 
                XMLNode* root = tree.root();
 
-               string description = _("No Description");
-               XMLNode* desc = tree.root()->child ("description");
-               if (desc) {
-                       description = desc->attribute_value ();
-               }
-
                TemplateInfo rti;
 
+               rti.created_with = _("(unknown)");
+               try {
+                       XMLNode *pv = root->child("ProgramVersion");
+                       string created_with;
+                       if (pv != 0) {
+                               pv->get_property (X_("created-with"), created_with);
+                       }
+                       rti.created_with = created_with;
+               } catch ( LIBPBD_API::XMLException &e) {}
+
+               rti.description = _("No Description");
+               try {
+                       XMLNode *desc = root->child("description");
+                       if (desc != 0) {
+                               rti.description = desc->attribute_value();
+                       }
+               } catch ( LIBPBD_API::XMLException &e) {}
+
                rti.name = IO::name_from_state (*root->children().front());
                rti.path = fullpath;
-               rti.description = description;
 
                template_names.push_back (rti);
        }