~ubuntu-branches/ubuntu/saucy/moin/saucy

« back to all changes in this revision

Viewing changes to MoinMoin/failure.py

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2008-11-13 16:45:52 UTC
  • mfrom: (0.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20081113164552-49t6zf2t2o5bqigh
Tags: 1.8.0-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Drop recommendation of python-xml, the packages isn't anymore in
    sys.path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
    @license: GNU GPL, see COPYING for details.
8
8
"""
9
9
import sys, os
 
10
import traceback
10
11
 
11
12
from MoinMoin import log
12
13
logging = log.getLogger(__name__)
13
14
 
14
15
from MoinMoin.support import cgitb
15
16
from MoinMoin.error import ConfigurationError
16
 
from traceback import extract_tb
17
17
 
18
18
 
19
19
class View(cgitb.View):
69
69
        text = [self.formatExceptionMessage(self.info)]
70
70
 
71
71
        if self.info[0] == ConfigurationError:
72
 
            tbt = extract_tb(self.info[1].exceptions()[-1][2])[-1]
 
72
            tbt = traceback.extract_tb(self.info[1].exceptions()[-1][2])[-1]
73
73
            text.append(
74
74
                f.paragraph('Error in your configuration file "%s"'
75
75
                            ' around line %d.' % tbt[:2]))
156
156
        raise err
157
157
 
158
158
    savedError = sys.exc_info()
159
 
    logging.exception('An exception occured.')
 
159
    logging.exception('An exception occurred, URI was "%s".' % request.request_uri)
 
160
 
160
161
    try:
161
 
        debug = 'debug' in getattr(request, 'form', {})
 
162
        display = request.cfg.traceback_show # might fail if we have no cfg yet
 
163
    except:
162
164
        # default to True here to allow an admin setting up the wiki
163
165
        # to see the errors made in the configuration file
164
166
        display = True
165
 
        logdir = None
166
 
        if hasattr(request, 'cfg'):
167
 
            display = request.cfg.traceback_show
168
 
            logdir = request.cfg.traceback_log_dir
169
 
        handler = cgitb.Hook(file=request, display=display, logdir=logdir,
170
 
                             viewClass=View, debug=debug)
171
 
        handler.handle()
172
 
    except:
 
167
 
 
168
    try:
 
169
        debug = 'debug' in request.form
 
170
    except:
 
171
        debug = False
 
172
 
 
173
    try:
 
174
        # try to output a nice html error page
 
175
        handler = cgitb.Hook(file=request, display=display, viewClass=View, debug=debug)
 
176
        handler.handle(savedError)
 
177
    except:
 
178
        # if that fails, log the cgitb problem ...
 
179
        logging.exception('cgitb raised this exception')
 
180
        # ... and try again with a simpler output method:
173
181
        request.write('<pre>\n')
174
 
        printTextException(request, savedError)
 
182
        printTextException(request, savedError, display)
175
183
        request.write('\nAdditionally cgitb raised this exception:\n')
176
 
        printTextException(request)
 
184
        printTextException(request, display=display)
177
185
        request.write('</pre>\n')
178
186
 
179
187
 
180
 
def printTextException(request, info=None):
 
188
 
 
189
def printTextException(request, info=None, display=True):
181
190
    """ Simple text exception that should never fail
182
191
 
183
192
    Print all exceptions in a composite error.
184
193
    """
185
 
    import traceback
 
194
    if not display:
 
195
        request.write("(Traceback display forbidden by configuration)\n")
 
196
        return
186
197
    from MoinMoin import wikiutil
187
198
    if info is None:
188
199
        info = sys.exc_info()