changeset 3277:3084b07ec266

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
author Richard Jones <richard@users.sourceforge.net>
date Wed, 13 Apr 2005 05:30:06 +0000
parents 3124e578db02
children 6e7462bbafde
files CHANGES.txt cgi-bin/roundup.cgi roundup/scripts/roundup_server.py
diffstat 3 files changed, 46 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Wed Apr 13 03:38:23 2005 +0000
+++ b/CHANGES.txt	Wed Apr 13 05:30:06 2005 +0000
@@ -15,12 +15,16 @@
   (see doc/upgrading.txt for how to fix in your trackers)
 - after logout, always display tracker home page
 - web forms don't create new items if no item properties are set from UI
-- item creation failed if multilink fields had invalid entries (sf bug 1177602)
+- item creation failed if multilink fields had invalid entries (sf bug
+  1177602)
 - fix bdist_rpm (sf bug 1164328)
 - fix checking of "Email Access" for Anonymous email registration (sf bug
   1177057)
 - disable "Email Access" for Anonymous by default to stop spam regsitering
   users on public trackers
+- 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
 
 
 2005-03-03 0.8.2
--- a/cgi-bin/roundup.cgi	Wed Apr 13 03:38:23 2005 +0000
+++ b/cgi-bin/roundup.cgi	Wed Apr 13 05:30:06 2005 +0000
@@ -16,12 +16,12 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: roundup.cgi,v 1.40 2004-07-27 00:57:17 richard Exp $
+# $Id: roundup.cgi,v 1.41 2005-04-13 05:30:06 richard Exp $
 
 # python version check
 from roundup import version_check
 from roundup.i18n import _
-import sys
+import sys, time
 
 #
 ##  Configuration
@@ -42,8 +42,9 @@
 # ROUNDUP_LOG is the name of the logfile; if it's empty or does not exist,
 # logging is turned off (unless you changed the default below). 
 
-# ROUNDUP_DEBUG is a debug level, currently only 0 (OFF) and 1 (ON) are
-# used in the code. Higher numbers means more debugging output. 
+# DEBUG_TO_CLIENT specifies whether debugging goes to the HTTP server (via
+# stderr) or to the web client (via cgitb).
+DEBUG_TO_CLIENT = False
 
 # This indicates where the Roundup tracker lives
 TRACKER_HOMES = {
@@ -211,7 +212,16 @@
 except:
     sys.stdout, sys.stderr = out, err
     out.write('Content-Type: text/html\n\n')
-    cgitb.handler()
+    if DEBUG_TO_CLIENT:
+        cgitb.handler()
+    else:
+        out.write(cgitb.breaker())
+        ts = time.ctime()
+        out.write('''<p>%s: An error occurred. Please check
+            the server log for more infomation.</p>'''%ts)
+        print >> sys.stderr, 'EXCEPTION AT', ts
+        traceback.print_exc(0, sys.stderr)
+
 sys.stdout.flush()
 sys.stdout, sys.stderr = out, err
 LOG.close()
--- a/roundup/scripts/roundup_server.py	Wed Apr 13 03:38:23 2005 +0000
+++ b/roundup/scripts/roundup_server.py	Wed Apr 13 05:30:06 2005 +0000
@@ -17,11 +17,11 @@
 
 """Command-line script that runs a server over roundup.cgi.client.
 
-$Id: roundup_server.py,v 1.77 2005-02-19 10:21:32 a1s Exp $
+$Id: roundup_server.py,v 1.78 2005-04-13 05:30:06 richard Exp $
 """
 __docformat__ = 'restructuredtext'
 
-import errno, cgi, getopt, os, socket, sys, traceback, urllib
+import errno, cgi, getopt, os, socket, sys, traceback, urllib, time
 import ConfigParser, BaseHTTPServer, SocketServer, StringIO
 
 # python version check
@@ -70,6 +70,7 @@
     TRACKER_HOMES = {}
     TRACKERS = None
     LOG_IPADDRESS = 1
+    DEBUG_MODE = False
 
     def get_tracker(self, name):
         """Return a tracker instance for given tracker name"""
@@ -116,16 +117,26 @@
                 self.send_response(400)
                 self.send_header('Content-Type', 'text/html')
                 self.end_headers()
-                try:
-                    reload(cgitb)
+                if self.DEBUG_MODE:
+                    try:
+                        reload(cgitb)
+                        self.wfile.write(cgitb.breaker())
+                        self.wfile.write(cgitb.html())
+                    except:
+                        s = StringIO.StringIO()
+                        traceback.print_exc(None, s)
+                        self.wfile.write("<pre>")
+                        self.wfile.write(cgi.escape(s.getvalue()))
+                        self.wfile.write("</pre>\n")
+                else:
+                    # user feedback
                     self.wfile.write(cgitb.breaker())
-                    self.wfile.write(cgitb.html())
-                except:
-                    s = StringIO.StringIO()
-                    traceback.print_exc(None, s)
-                    self.wfile.write("<pre>")
-                    self.wfile.write(cgi.escape(s.getvalue()))
-                    self.wfile.write("</pre>\n")
+                    ts = time.ctime()
+                    self.wfile.write('''<p>%s: An error occurred. Please check
+                    the server log for more infomation.</p>'''%ts)
+                    # out to the logfile
+                    print 'EXCEPTION AT', ts
+                    traceback.print_exc()
         sys.stdin = save_stdin
 
     do_GET = do_POST = do_HEAD = run_cgi
@@ -405,6 +416,7 @@
         """Return HTTP server object to run"""
         # we don't want the cgi module interpreting the command-line args ;)
         sys.argv = sys.argv[:1]
+
         # preload all trackers unless we are in "debug" mode
         tracker_homes = self.trackers()
         if self["MULTIPROCESS"] == "debug":
@@ -412,11 +424,14 @@
         else:
             trackers = dict([(name, roundup.instance.open(home, optimize=1))
                 for (name, home) in tracker_homes])
+
         # build customized request handler class
         class RequestHandler(RoundupRequestHandler):
             LOG_IPADDRESS = not self["LOG_HOSTNAMES"]
             TRACKER_HOMES = dict(tracker_homes)
             TRACKERS = trackers
+            DEBUG_MODE = self["MULTIPROCESS"] == "debug"
+
         # obtain request server class
         if self["MULTIPROCESS"] not in MULTIPROCESS_TYPES:
             print _("Multiprocess mode \"%s\" is not available, "

Roundup Issue Tracker: http://roundup-tracker.org/