Commits

Thomas Waldmann committed df3e722

catch exceptions happening in the converters, show time/url for crash and hint to look into the log file

Comments (0)

Files changed (2)

MoinMoin/items/content.py

         return doc
 
     def _render_data(self):
-        from MoinMoin.converter import default_registry as reg
-        # TODO: Real output format
-        doc = self.internal_representation()
-        doc = self._expand_document(doc)
-        flaskg.clock.start('conv_dom_html')
-        html_conv = reg.get(type_moin_document, Type('application/x-xhtml-moin-page'))
-        doc = html_conv(doc)
-        flaskg.clock.stop('conv_dom_html')
-        rendered_data = conv_serialize(doc, {html.namespace: ''})
+        try:
+            from MoinMoin.converter import default_registry as reg
+            # TODO: Real output format
+            doc = self.internal_representation()
+            doc = self._expand_document(doc)
+            flaskg.clock.start('conv_dom_html')
+            html_conv = reg.get(type_moin_document, Type('application/x-xhtml-moin-page'))
+            doc = html_conv(doc)
+            flaskg.clock.stop('conv_dom_html')
+            rendered_data = conv_serialize(doc, {html.namespace: ''})
+        except Exception:
+            # we really want to make sure that invalid data or a malfunctioning
+            # converter does not crash the item view (otherwise a user might
+            # not be able to fix it from the UI).
+            logging.exception("An exception happened in _render_data:")
+            import time
+            rendered_data = render_template('crash.html',
+                                            server_time=time.strftime("%Y-%m-%d %H:%M:%S %Z"),
+                                            url=request.url)
         return rendered_data
 
     def _render_data_xml(self):

MoinMoin/templates/crash.html

+<h1>{{ _("Boom!") }}</h1>
+<p>
+    {{ _("An error happened while rendering the data.") }}
+</p>
+<p>
+    {{ _("More details are in the server log. Time and URL are helpful for locating the corresponding log entries:") }}
+</p>
+<dl>
+    <dt>{{ _("Server time") }}</dt>
+    <dd>{{ server_time }}</dd>
+    <dt>{{ _("URL") }}</dt>
+    <dd>{{ url }} </dd>
+</dl>