]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Include the top XML sections in an error message. 3251/head
authorDavid Wells <wellsd2@rpi.edu>
Sat, 15 Oct 2016 13:19:16 +0000 (09:19 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Sat, 15 Oct 2016 13:56:07 +0000 (09:56 -0400)
This commit improves ExcInvalidXMLParameterFile by printing out the
names of the top level XML sections in an exception message.

source/base/parameter_handler.cc
tests/parameter_handler/parameter_handler_read_xml_error_03.output

index a74c234ddb3f8f2d76dbeffac82fe73c10ac173d..509c15b4d15f00c01c748e4d7d184dd47ef1c29f 100644 (file)
@@ -1936,11 +1936,29 @@ void ParameterHandler::parse_input_from_xml (std::istream &in)
 
   const std::size_t n_top_level_elements = std::distance (single_node_tree.begin(),
                                                           single_node_tree.end());
-  AssertThrow (n_top_level_elements == 1,
-               ExcInvalidXMLParameterFile ("There are "
-                                           + Utilities::to_string(n_top_level_elements)
-                                           + " top-level elements, but there "
-                                           "should only be one."));
+  if (n_top_level_elements != 1)
+    {
+      std::ostringstream top_level_message;
+      top_level_message << "The ParameterHandler input parser found "
+                        << n_top_level_elements
+                        << " top level elements while reading\n "
+                        << "    an XML format input file, but there should be"
+                        << " exactly one top level element.\n"
+                        << "    The top level elements are:\n";
+
+      unsigned int entry_n = 0;
+      for (boost::property_tree::ptree::iterator it = single_node_tree.begin();
+           it != single_node_tree.end(); ++it, ++entry_n)
+        {
+          top_level_message << "        "
+                            << it->first
+                            << (entry_n != n_top_level_elements - 1 ? "\n" : "");
+        }
+
+      // repeat assertion condition to make the printed version easier to read
+      AssertThrow (n_top_level_elements == 1,
+                   ExcInvalidXMLParameterFile (top_level_message.str()));
+    }
 
   // read the child elements recursively
   const boost::property_tree::ptree
index 71bf9d00491a09295d1a60bf3b4a9d5132a86f6b..bc2128a0f5cc2f87e46d5b6cfeefcc54c35cb545 100644 (file)
@@ -1,3 +1,7 @@
 
-DEAL::ExcInvalidXMLParameterFile ("There are " + Utilities::to_string(n_top_level_elements) + " top-level elements, but there " "should only be one.")
-There are 2 top-level elements, but there should only be one.
+DEAL::ExcInvalidXMLParameterFile (top_level_message.str())
+    The ParameterHandler input parser found 2 top level elements while reading
+    an XML format input file, but there should be exactly one top level element.
+    The top level elements are:
+        ParameterHandler
+        secondtopleveltag

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.