[gobject-introspection: 22/30] docwriter: Handle invalid nodes better

commit fc39530d66d921331ced5a0b6607e9106c8d1647
Author: Philip Chimento <philip chimento gmail com>
Date:   Tue Feb 9 22:24:15 2016 -0800

    docwriter: Handle invalid nodes better
    Cogl-2.0.gir has the following entry:
        <bitfield name="BufferMapHint"
          <doc xml:whitespace="preserve">...</doc>
          <member name="" value="1"
            <doc xml:whitespace="preserve">...</doc>
          <member name="_range"
            <doc xml:whitespace="preserve">...</doc>
    The prefix is not picked up correctly and so we get a member without a
    name, which crashes the docwriter in to_underscore(). Change that
    function to handle this case by giving it a dummy "anonymous member"

 giscanner/docwriter.py | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff --git a/giscanner/docwriter.py b/giscanner/docwriter.py
index e5a025ba..754787e3 100644
--- a/giscanner/docwriter.py
+++ b/giscanner/docwriter.py
@@ -28,6 +28,7 @@ from __future__ import unicode_literals
 import os
 import re
+import sys
 import tempfile
 from xml.sax import saxutils
@@ -1131,6 +1132,15 @@ class DevDocsFormatterGjs(DocFormatterGjs):
             link += "#" + anchor
         return "[{}]({}){}".format(display_name, link, 's' if pluralize else '')
+    def to_underscores(self, node):
+        try:
+            return super(DevDocsFormatterGjs, self).to_underscores(node)
+        except Exception as e:
+            if e.message == 'invalid node':
+                print('warning: invalid node in', node.parent.name,
+                    file=sys.stderr)
+                return node.parent.name + '_invalid_node'
     def make_anchor(self, node):
         style_class = get_node_kind(node)
         return "{}-{}".format(style_class, self.to_underscores(node))

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]