chiark / gitweb /
doxygen: don't die on XML parse error.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 29 Jan 2018 19:49:14 +0000 (20:49 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Mon, 29 Jan 2018 22:51:19 +0000 (23:51 +0100)
Doxygen is able to highlight PNGs as C++ code. It's amazing, of
course, but the result is a terrible mess (of course). So let's have
another drink and ignore those *amazing things*.

doxygen/dox2html5.py
doxygen/test/contents_parse_error/Doxyfile [new file with mode: 0644]
doxygen/test/contents_parse_error/broken.xml [new file with mode: 0644]
doxygen/test/test_contents.py

index 93176e850c5321747807d0c21c19acd96b8f8d0e..a921cc4ffa441d806ad5c202850fe3d8c8c3f71f 100755 (executable)
@@ -1147,7 +1147,12 @@ def parse_define(state: State, element: ET.Element):
 def extract_metadata(state: State, xml):
     logging.debug("Extracting metadata from {}".format(os.path.basename(xml)))
 
-    tree = ET.parse(xml)
+    try:
+        tree = ET.parse(xml)
+    except ET.ParseError as e:
+        logging.error("{}: XML parse error, skipping: {}".format(os.path.basename(xml), e))
+        return
+
     root = tree.getroot()
 
     # We need just list of all example files in correct order, nothing else
@@ -1281,7 +1286,12 @@ def parse_xml(state: State, xml: str):
 
     logging.debug("Parsing {}".format(state.current))
 
-    tree = ET.parse(xml)
+    try:
+        tree = ET.parse(xml)
+    except ET.ParseError as e:
+        logging.error("{}: XML parse error, skipping: {}".format(state.current, e))
+        return
+
     root = tree.getroot()
     assert root.tag == 'doxygen'
 
diff --git a/doxygen/test/contents_parse_error/Doxyfile b/doxygen/test/contents_parse_error/Doxyfile
new file mode 100644 (file)
index 0000000..8ec4cc4
--- /dev/null
@@ -0,0 +1 @@
+XML_OUTPUT              =
diff --git a/doxygen/test/contents_parse_error/broken.xml b/doxygen/test/contents_parse_error/broken.xml
new file mode 100644 (file)
index 0000000..7d69da7
--- /dev/null
@@ -0,0 +1 @@
+&<><><><>
index 122122c62c8442c35def7e5d77d8a04c898d728f..831f29fe185b93c92614c50aac283af026fbcaf8 100644 (file)
@@ -28,7 +28,7 @@ import unittest
 
 from distutils.version import LooseVersion
 
-from test import IntegrationTestCase, doxygen_version
+from test import BaseTestCase, IntegrationTestCase, doxygen_version
 
 class Typography(IntegrationTestCase):
     def __init__(self, *args, **kwargs):
@@ -139,3 +139,13 @@ class Custom(IntegrationTestCase):
     def test_math(self):
         self.run_dox2html5(wildcard='math.xml')
         self.assertEqual(*self.actual_expected_contents('math.html'))
+
+class ParseError(BaseTestCase):
+    def __init__(self, *args, **kwargs):
+        super().__init__(__file__, 'parse_error', *args, **kwargs)
+
+    def test(self):
+        self.run_dox2html5(wildcard='broken.xml')
+
+        # The index file should be generated, no abort
+        self.assertTrue(os.path.exists(os.path.join(self.path, 'html', 'index.html')))