annotate MoinMoin/failure.py @ 4468:fad2936d33a7 1.8.1

added dummy mig script for 1.8.1, bumped version number
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 24 Dec 2008 16:32:46 +0100
parents 888574a117e6
children
rev   line source
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
2 """ MoinMoin failure
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
3
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1593
diff changeset
4 Handle fatal errors by showing a message and debugging information.
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
5
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1593
diff changeset
6 @copyright: 2004-2005 Nir Soffer <nirs@freeshell.org>
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1593
diff changeset
7 @license: GNU GPL, see COPYING for details.
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
8 """
3110
a48929a5036c logging: make it work correctly by doing logging configuration very early
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2379
diff changeset
9 import sys, os
3771
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
10 import traceback
3110
a48929a5036c logging: make it work correctly by doing logging configuration very early
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2379
diff changeset
11
a48929a5036c logging: make it work correctly by doing logging configuration very early
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2379
diff changeset
12 from MoinMoin import log
a48929a5036c logging: make it work correctly by doing logging configuration very early
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2379
diff changeset
13 logging = log.getLogger(__name__)
1586
cae5575b07fa log tracebacks
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 931
diff changeset
14
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
15 from MoinMoin.support import cgitb
2379
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
16 from MoinMoin.error import ConfigurationError
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
17
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
18
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
19 class View(cgitb.View):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
20 """ Display an error message and debugging information
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2205
diff changeset
21
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
22 Additions to cgitb.View:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
23 - Multiple tracebacks support
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
24 - Debugging information is shown only in debug mode
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
25 - Moin application information
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
26 - General help text and links
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
27 - Handle multiple paragraphs in exception message
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2205
diff changeset
28
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
29 cgitb is heavily modified cgitb, but fully backward compatible with
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2205
diff changeset
30 the standard cgitb. It should not contain any moin specific code.
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
31
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
32 cgitb was refactored to be easy to customize by applications
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
33 developers. This moin specific subclass is an example.
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
34 """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
35 debugInfoID = 'debug-info'
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
36
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
37 def formatContent(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
38 content = (
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
39 self.script(),
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
40 self.formatStylesheet(),
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
41 self.formatTitle(),
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
42 self.formatMessage(),
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
43 self.formatButtons(),
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
44 self.formatDebugInfo(),
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
45 self.formatTextTraceback()
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
46 )
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
47 return ''.join(content)
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
48
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
49 def script(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
50 return '''
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
51 <script type="text/javascript">
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
52 function toggleDebugInfo() {
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
53 var tb = document.getElementById('%s');
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
54 if (tb == null) return;
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
55 tb.style.display = tb.style.display ? '' : 'none';
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
56 }
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
57 </script>
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
58 ''' % self.debugInfoID
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
59
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
60 def stylesheet(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
61 return cgitb.View.stylesheet(self) + """
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2205
diff changeset
62 .cgitb .buttons {margin: 0.5em 0; padding: 5px 10px;}
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
63 .cgitb .buttons li {display: inline; margin: 0; padding: 0 0.25em;}
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
64 """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
65
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
66 def formatMessage(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
67 """ handle multiple paragraphs messages and add general help """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
68 f = self.formatter
2379
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
69 text = [self.formatExceptionMessage(self.info)]
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
70
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
71 if self.info[0] == ConfigurationError:
3771
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
72 tbt = traceback.extract_tb(self.info[1].exceptions()[-1][2])[-1]
2379
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
73 text.append(
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
74 f.paragraph('Error in your configuration file "%s"'
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
75 ' around line %d.' % tbt[:2]))
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
76 else:
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
77 text.append(
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
78 f.paragraph("If you want to report a bug, please save "
2379
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
79 "this page and attach it to your bug report."))
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
80 return ''.join(text)
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
81
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
82 def formatButtons(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
83 """ Add 'buttons' to the error dialog """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
84 f = self.formatter
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
85 buttons = [f.link('javascript:toggleDebugInfo()',
2379
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
86 'Show debugging information')]
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
87 if self.info[0] != ConfigurationError:
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
88 buttons.append(
3115
cd6cfc715261 replace wikiwikiweb.de by moinmo.in, replace contact Juergen Hermann by Thomas Waldmann, cleanup wikiconfig (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3110
diff changeset
89 f.link('http://moinmo.in/MoinMoinBugs',
2379
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
90 'Report bug'))
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
91 buttons.append(
3115
cd6cfc715261 replace wikiwikiweb.de by moinmo.in, replace contact Juergen Hermann by Thomas Waldmann, cleanup wikiconfig (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3110
diff changeset
92 f.link('http://moinmo.in/FrontPage',
2379
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
93 'Visit MoinMoin wiki'))
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
94 return f.list(buttons, {'class': 'buttons'})
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
95
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
96 def formatDebugInfo(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
97 """ Put debugging information in a hidden div """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
98 attributes = {'id': self.debugInfoID}
52
80b3d4e891ff merge moin--main--1.3--patch-931: fix hidding of huge tracebacks
Nir Soffer <nirs@freeshell.org>
parents: 49
diff changeset
99 info = [self.debugInfoHideScript(),
80b3d4e891ff merge moin--main--1.3--patch-931: fix hidding of huge tracebacks
Nir Soffer <nirs@freeshell.org>
parents: 49
diff changeset
100 self.formatTraceback(),
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
101 self.formatSystemDetails(), ]
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
102 return self.formatter.section(''.join(info), attributes)
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
103
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
104 def debugInfoHideScript(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
105 """ Hide debug info for javascript enabled browsers """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
106 if self.debug:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
107 return ''
52
80b3d4e891ff merge moin--main--1.3--patch-931: fix hidding of huge tracebacks
Nir Soffer <nirs@freeshell.org>
parents: 49
diff changeset
108 return '''
80b3d4e891ff merge moin--main--1.3--patch-931: fix hidding of huge tracebacks
Nir Soffer <nirs@freeshell.org>
parents: 49
diff changeset
109 <script type="text/javascript">toggleDebugInfo()</script>
80b3d4e891ff merge moin--main--1.3--patch-931: fix hidding of huge tracebacks
Nir Soffer <nirs@freeshell.org>
parents: 49
diff changeset
110 '''
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
111
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
112 def formatTraceback(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
113 return self.formatAllTracebacks(self.formatOneTraceback)
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
114
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
115 def formatTextTraceback(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
116 template = self.textTracebackTemplate()
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
117 return template % self.formatAllTracebacks(self.formatOneTextTraceback)
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
118
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
119 def formatAllTracebacks(self, formatFuction):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
120 """ Format multiple tracebacks using formatFunction """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
121 tracebacks = []
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
122 for ttype, tvalue, tb in self.exceptions():
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
123 if ttype is None:
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
124 break
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
125 tracebacks.append(formatFuction((ttype, tvalue, tb)))
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
126 del tb
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
127 return ''.join(tracebacks)
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
128
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
129 def exceptions(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
130 """ Return a list of exceptions info, starting at self.info """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
131 try:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
132 return [self.info] + self.info[1].exceptions()
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
133 except AttributeError:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
134 return [self.info]
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
135
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
136 def applicationDetails(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
137 """ Add MoinMoin details to system details """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
138 from MoinMoin import version
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
139 return ['MoinMoin: Release %s (%s)' % (version.release,
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
140 version.revision)]
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
141
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
142 def formatExceptionMessage(self, info):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
143 """ Handle multiple paragraphs in exception message """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
144 text = cgitb.View.exceptionMessage(self, info)
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
145 text = text.split('\n\n')
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
146 text = ''.join([self.formatter.paragraph(item) for item in text])
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
147 return text
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
148
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
149
1586
cae5575b07fa log tracebacks
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 931
diff changeset
150 def handle(request, err):
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
151 """ Handle failures
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2205
diff changeset
152
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
153 Display fancy error view, or fallback to simple text traceback
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
154 """
1588
8a7643aae797 Forward exceptions if MOIN_DEBUG is set in os.environment to Python debugger
Raphael Bossek <raphael.bossek@gmx.de>
parents: 1586
diff changeset
155 if 'MOIN_DEBUG' in os.environ:
8a7643aae797 Forward exceptions if MOIN_DEBUG is set in os.environment to Python debugger
Raphael Bossek <raphael.bossek@gmx.de>
parents: 1586
diff changeset
156 raise err
8a7643aae797 Forward exceptions if MOIN_DEBUG is set in os.environment to Python debugger
Raphael Bossek <raphael.bossek@gmx.de>
parents: 1586
diff changeset
157
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
158 savedError = sys.exc_info()
3809
888574a117e6 log exception causing URI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3771
diff changeset
159 logging.exception('An exception occurred, URI was "%s".' % request.request_uri)
3771
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
160
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
161 try:
3771
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
162 display = request.cfg.traceback_show # might fail if we have no cfg yet
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
163 except:
2379
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
164 # default to True here to allow an admin setting up the wiki
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
165 # to see the errors made in the configuration file
24bfe5789665 fix traceback when there are errors in the config file, don't tell people to report a bug for that
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
166 display = True
3771
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
167
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
168 try:
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
169 debug = 'debug' in request.form
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
170 except:
3771
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
171 debug = False
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
172
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
173 try:
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
174 # try to output a nice html error page
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
175 handler = cgitb.Hook(file=request, display=display, viewClass=View, debug=debug)
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
176 handler.handle(savedError)
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
177 except:
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
178 # if that fails, log the cgitb problem ...
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
179 logging.exception('cgitb raised this exception')
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
180 # ... and try again with a simpler output method:
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
181 request.write('<pre>\n')
3771
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
182 printTextException(request, savedError, display)
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
183 request.write('\nAdditionally cgitb raised this exception:\n')
3771
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
184 printTextException(request, display=display)
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
185 request.write('</pre>\n')
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
186
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
187
3771
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
188
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
189 def printTextException(request, info=None, display=True):
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
190 """ Simple text exception that should never fail
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2205
diff changeset
191
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
192 Print all exceptions in a composite error.
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
193 """
3771
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
194 if not display:
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
195 request.write("(Traceback display forbidden by configuration)\n")
c57d79281471 error handling: remove cfg.traceback_log_dir (we just use logging.exception), only output text tracebacks if allowed by cfg.traceback_show
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3156
diff changeset
196 return
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
197 from MoinMoin import wikiutil
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
198 if info is None:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
199 info = sys.exc_info()
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
200 try:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
201 exceptions = [info] + info[1].exceptions()
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
202 except AttributeError:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
203 exceptions = [info]
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
204 for info in exceptions:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
205 text = ''.join(traceback.format_exception(*info))
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
206 text = wikiutil.escape(text)
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
207 request.write(text)
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
208