7
7
@license: GNU GPL, see COPYING for details.
11
12
from MoinMoin import log
12
13
logging = log.getLogger(__name__)
14
15
from MoinMoin.support import cgitb
15
16
from MoinMoin.error import ConfigurationError
16
from traceback import extract_tb
19
19
class View(cgitb.View):
69
69
text = [self.formatExceptionMessage(self.info)]
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]
74
74
f.paragraph('Error in your configuration file "%s"'
75
75
' around line %d.' % tbt[:2]))
158
158
savedError = sys.exc_info()
159
logging.exception('An exception occured.')
159
logging.exception('An exception occurred, URI was "%s".' % request.request_uri)
161
debug = 'debug' in getattr(request, 'form', {})
162
display = request.cfg.traceback_show # might fail if we have no cfg yet
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
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)
169
debug = 'debug' in request.form
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)
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')
180
def printTextException(request, info=None):
189
def printTextException(request, info=None, display=True):
181
190
""" Simple text exception that should never fail
183
192
Print all exceptions in a composite error.
195
request.write("(Traceback display forbidden by configuration)\n")
186
197
from MoinMoin import wikiutil
188
199
info = sys.exc_info()