Skip to content

Commit 7a2c2ed

Browse files
author
Richard Jones
committed
send errors in the web interface to a logfile by default.
Use the "debug" multiprocess mode (roundup-server) or the DEBUG_TO_CLIENT var (roundup.cgi) to have the errors appear in your browser
1 parent 6c47476 commit 7a2c2ed

File tree

3 files changed

+46
-17
lines changed

3 files changed

+46
-17
lines changed

CHANGES.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ Fixed:
1515
(see doc/upgrading.txt for how to fix in your trackers)
1616
- after logout, always display tracker home page
1717
- web forms don't create new items if no item properties are set from UI
18-
- item creation failed if multilink fields had invalid entries (sf bug 1177602)
18+
- item creation failed if multilink fields had invalid entries (sf bug
19+
1177602)
1920
- fix bdist_rpm (sf bug 1164328)
2021
- fix checking of "Email Access" for Anonymous email registration (sf bug
2122
1177057)
2223
- disable "Email Access" for Anonymous by default to stop spam regsitering
2324
users on public trackers
25+
- send errors in the web interface to a logfile by default. Use the
26+
"debug" multiprocess mode (roundup-server) or the DEBUG_TO_CLIENT var
27+
(roundup.cgi) to have the errors appear in your browser
2428

2529

2630
2005-03-03 0.8.2

cgi-bin/roundup.cgi

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: roundup.cgi,v 1.40 2004-07-27 00:57:17 richard Exp $
19+
# $Id: roundup.cgi,v 1.41 2005-04-13 05:30:06 richard Exp $
2020

2121
# python version check
2222
from roundup import version_check
2323
from roundup.i18n import _
24-
import sys
24+
import sys, time
2525

2626
#
2727
## Configuration
@@ -42,8 +42,9 @@ import sys
4242
# ROUNDUP_LOG is the name of the logfile; if it's empty or does not exist,
4343
# logging is turned off (unless you changed the default below).
4444

45-
# ROUNDUP_DEBUG is a debug level, currently only 0 (OFF) and 1 (ON) are
46-
# used in the code. Higher numbers means more debugging output.
45+
# DEBUG_TO_CLIENT specifies whether debugging goes to the HTTP server (via
46+
# stderr) or to the web client (via cgitb).
47+
DEBUG_TO_CLIENT = False
4748

4849
# This indicates where the Roundup tracker lives
4950
TRACKER_HOMES = {
@@ -211,7 +212,16 @@ except SystemExit:
211212
except:
212213
sys.stdout, sys.stderr = out, err
213214
out.write('Content-Type: text/html\n\n')
214-
cgitb.handler()
215+
if DEBUG_TO_CLIENT:
216+
cgitb.handler()
217+
else:
218+
out.write(cgitb.breaker())
219+
ts = time.ctime()
220+
out.write('''<p>%s: An error occurred. Please check
221+
the server log for more infomation.</p>'''%ts)
222+
print >> sys.stderr, 'EXCEPTION AT', ts
223+
traceback.print_exc(0, sys.stderr)
224+
215225
sys.stdout.flush()
216226
sys.stdout, sys.stderr = out, err
217227
LOG.close()

roundup/scripts/roundup_server.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
"""Command-line script that runs a server over roundup.cgi.client.
1919
20-
$Id: roundup_server.py,v 1.77 2005-02-19 10:21:32 a1s Exp $
20+
$Id: roundup_server.py,v 1.78 2005-04-13 05:30:06 richard Exp $
2121
"""
2222
__docformat__ = 'restructuredtext'
2323

24-
import errno, cgi, getopt, os, socket, sys, traceback, urllib
24+
import errno, cgi, getopt, os, socket, sys, traceback, urllib, time
2525
import ConfigParser, BaseHTTPServer, SocketServer, StringIO
2626

2727
# python version check
@@ -70,6 +70,7 @@ class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
7070
TRACKER_HOMES = {}
7171
TRACKERS = None
7272
LOG_IPADDRESS = 1
73+
DEBUG_MODE = False
7374

7475
def get_tracker(self, name):
7576
"""Return a tracker instance for given tracker name"""
@@ -116,16 +117,26 @@ def run_cgi(self):
116117
self.send_response(400)
117118
self.send_header('Content-Type', 'text/html')
118119
self.end_headers()
119-
try:
120-
reload(cgitb)
120+
if self.DEBUG_MODE:
121+
try:
122+
reload(cgitb)
123+
self.wfile.write(cgitb.breaker())
124+
self.wfile.write(cgitb.html())
125+
except:
126+
s = StringIO.StringIO()
127+
traceback.print_exc(None, s)
128+
self.wfile.write("<pre>")
129+
self.wfile.write(cgi.escape(s.getvalue()))
130+
self.wfile.write("</pre>\n")
131+
else:
132+
# user feedback
121133
self.wfile.write(cgitb.breaker())
122-
self.wfile.write(cgitb.html())
123-
except:
124-
s = StringIO.StringIO()
125-
traceback.print_exc(None, s)
126-
self.wfile.write("<pre>")
127-
self.wfile.write(cgi.escape(s.getvalue()))
128-
self.wfile.write("</pre>\n")
134+
ts = time.ctime()
135+
self.wfile.write('''<p>%s: An error occurred. Please check
136+
the server log for more infomation.</p>'''%ts)
137+
# out to the logfile
138+
print 'EXCEPTION AT', ts
139+
traceback.print_exc()
129140
sys.stdin = save_stdin
130141

131142
do_GET = do_POST = do_HEAD = run_cgi
@@ -405,18 +416,22 @@ def get_server(self):
405416
"""Return HTTP server object to run"""
406417
# we don't want the cgi module interpreting the command-line args ;)
407418
sys.argv = sys.argv[:1]
419+
408420
# preload all trackers unless we are in "debug" mode
409421
tracker_homes = self.trackers()
410422
if self["MULTIPROCESS"] == "debug":
411423
trackers = None
412424
else:
413425
trackers = dict([(name, roundup.instance.open(home, optimize=1))
414426
for (name, home) in tracker_homes])
427+
415428
# build customized request handler class
416429
class RequestHandler(RoundupRequestHandler):
417430
LOG_IPADDRESS = not self["LOG_HOSTNAMES"]
418431
TRACKER_HOMES = dict(tracker_homes)
419432
TRACKERS = trackers
433+
DEBUG_MODE = self["MULTIPROCESS"] == "debug"
434+
420435
# obtain request server class
421436
if self["MULTIPROCESS"] not in MULTIPROCESS_TYPES:
422437
print _("Multiprocess mode \"%s\" is not available, "

0 commit comments

Comments
 (0)