changeset 2379:24bfe5789665

fix traceback when there are errors in the config file, don't tell people to report a bug for that
author Johannes Berg <johannes AT sipsolutions DOT net>
date Tue, 17 Jul 2007 12:32:27 +0200
parents a7f4b02f5fdb
children 0d04c8c82eb6
files MoinMoin/failure.py
diffstat 1 files changed, 26 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/failure.py	Sun Jul 15 16:34:25 2007 +0200
+++ b/MoinMoin/failure.py	Tue Jul 17 12:32:27 2007 +0200
@@ -9,6 +9,8 @@
 import sys, os, logging
 
 from MoinMoin.support import cgitb
+from MoinMoin.error import ConfigurationError
+from traceback import extract_tb
 
 
 class View(cgitb.View):
@@ -61,20 +63,31 @@
     def formatMessage(self):
         """ handle multiple paragraphs messages and add general help """
         f = self.formatter
-        text = [self.formatExceptionMessage(self.info),
+        text = [self.formatExceptionMessage(self.info)]
+
+        if self.info[0] == ConfigurationError:
+            tbt = extract_tb(self.info[1].exceptions()[-1][2])[-1]
+            text.append(
+                f.paragraph('Error in your configuration file "%s"'
+                            ' around line %d.' % tbt[:2]))
+        else:
+            text.append(
                 f.paragraph("If you want to report a bug, please save "
-                            "this page and  attach it to your bug report."), ]
+                            "this page and  attach it to your bug report."))
         return ''.join(text)
 
     def formatButtons(self):
         """ Add 'buttons' to the error dialog """
         f = self.formatter
         buttons = [f.link('javascript:toggleDebugInfo()',
-                          'Show debugging information'),
+                          'Show debugging information')]
+        if self.info[0] != ConfigurationError:
+            buttons.append(
                    f.link('http://moinmoin.wikiwikiweb.de/MoinMoinBugs',
-                          'Report bug'),
+                          'Report bug'))
+            buttons.append(
                    f.link('http://moinmoin.wikiwikiweb.de/FrontPage',
-                          'Visit MoinMoin wiki'), ]
+                          'Visit MoinMoin wiki'))
         return f.list(buttons, {'class': 'buttons'})
 
     def formatDebugInfo(self):
@@ -143,9 +156,14 @@
     logging.error('%s: %s' % (err.__class__.__name__, str(err)), exc_info=savedError)
     try:
         debug = 'debug' in getattr(request, 'form', {})
-        handler = cgitb.Hook(file=request,
-                             display=request.cfg.traceback_show,
-                             logdir=request.cfg.traceback_log_dir,
+        # default to True here to allow an admin setting up the wiki
+        # to see the errors made in the configuration file
+        display = True
+        logdir = None
+        if hasattr(request, 'cfg'):
+            display = request.cfg.traceback_show
+            logdir = request.cfg.traceback_log_dir
+        handler = cgitb.Hook(file=request, display=display, logdir=logdir,
                              viewClass=View, debug=debug)
         handler.handle()
     except: