Avoid assert() when loading xml: Throw an XMLerror if attribute_value fails.
authorBen Loftis <ben@harrisonconsoles.com>
Wed, 30 Aug 2017 14:32:21 +0000 (09:32 -0500)
committerBen Loftis <ben@harrisonconsoles.com>
Wed, 30 Aug 2017 15:23:34 +0000 (10:23 -0500)
libs/pbd/pbd/xml++.h
libs/pbd/xml++.cc

index 4b012c910e6d5b8fdc064cc5b899f46aee0531b4..2ca9375ec3a6a9fd0a5252e7545cdb5bf84d22d7 100644 (file)
@@ -131,7 +131,7 @@ public:
        XMLNode* add_child_copy(const XMLNode&);
        void     add_child_nocopy(XMLNode&);
 
-       std::string attribute_value();
+       std::string attribute_value();  //throws XMLException if attribute doesn't exist
 
        const XMLPropertyList& properties() const { return _proplist; }
        XMLProperty const *    property(const char*) const;
index 23ecfabc9146e7e8a87d76159d582f55af85e65b..c18d36f065addd195ca543ca4f8e053c011aa274 100644 (file)
@@ -466,10 +466,16 @@ std::string
 XMLNode::attribute_value()
 {
        XMLNodeList children = this->children();
-       assert(!_is_content);
-       assert(children.size() == 1);
+       if (_is_content)
+               throw XMLException("XMLNode: attribute_value failed (is_content) for requested node: " + name());
+
+       if (children.size() != 1)
+               throw XMLException("XMLNode: attribute_value failed (children.size != 1) for requested node: " + name());
+
        XMLNode* child = *(children.begin());
-       assert(child->is_content());
+       if (!child->is_content())
+               throw XMLException("XMLNode: attribute_value failed (!child->is_content()) for requested node: " + name());
+
        return child->content();
 }