Code

Improve error reporting.
authorstefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2>
Fri, 9 Oct 2009 13:13:32 +0000 (13:13 +0000)
committerstefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2>
Fri, 9 Oct 2009 13:13:32 +0000 (13:13 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4368 57a73879-2fb5-44c3-a270-3262357dd7e2

roundup/cgi/cgitb.py
roundup/cgi/client.py

index 50ea47576b0328ee308a48daf261f8e44724828c..b89cb467bde0ba025fcf3c66a1a23053f98a492f 100644 (file)
@@ -37,7 +37,10 @@ def breaker():
 
 def niceDict(indent, dict):
     l = []
-    for k,v in dict.items():
+    keys = dict.keys()
+    keys.sort()
+    for k in keys:
+        v = dict[k]
         l.append('<tr><td><strong>%s</strong></td><td>%s</td></tr>'%(k,
             cgi.escape(repr(v))))
     return '\n'.join(l)
index 13db91ceb46dd4634b0a4b3022e6727dad28f823..ea973f33ff5ddfc28b6879f15042ec94c9c8a689 100644 (file)
@@ -515,11 +515,22 @@ class Client:
             self.error_message.append(self._('Form Error: ') + str(e))
             self.write_html(self.renderContext())
         except:
-            if self.instance.config.WEB_DEBUG:
-                self.write_html(cgitb.html(i18n=self.translator))
+            # Something has gone badly wrong.  Therefore, we should
+            # make sure that the response code indicates failure.
+            if self.response_code == httplib.OK:
+                self.response_code = httplib.INTERNAL_SERVER_ERROR
+            # Help the administrator work out what went wrong.
+            html = ("<h1>Traceback</h1>"
+                    + cgitb.html(i18n=self.translator)
+                    + ("<h1>Environment Variables</h1><table>%s</table>"
+                       % cgitb.niceDict("", self.env)))
+            if not self.instance.config.WEB_DEBUG:
+                exc_info = sys.exc_info()
+                subject = "Error: %s" % exc_info[1]
+                self.send_html_to_admin(subject, html)
+                self.write_html(self._(error_message))
             else:
-                self.mailer.exception_message()
-                return self.write_html(self._(error_message))
+                self.write_html(html)
 
     def clean_sessions(self):
         """Deprecated
@@ -950,6 +961,17 @@ class Client:
             self.additional_headers['Content-Length'] = str(len(content))
             self.write(content)
 
+    def send_html_to_admin(self, subject, content):
+
+        to = [self.mailer.config.ADMIN_EMAIL]
+        message = self.mailer.get_standard_message(to, subject)
+        # delete existing content-type headers
+        del message['Content-type']
+        message['Content-type'] = 'text/html; charset=utf-8'
+        message.set_payload(content)
+        encode_quopri(message)
+        self.mailer.smtp_send(to, str(message))
+    
     def renderContext(self):
         """ Return a PageTemplate for the named page
         """
@@ -996,16 +1018,8 @@ class Client:
             try:
                 # If possible, send the HTML page template traceback
                 # to the administrator.
-                to = [self.mailer.config.ADMIN_EMAIL]
                 subject = "Templating Error: %s" % exc_info[1]
-                content = cgitb.pt_html()
-                message = self.mailer.get_standard_message(to, subject)
-                # delete existing content-type headers
-                del message['Content-type']
-                message['Content-type'] = 'text/html; charset=utf-8'
-                message.set_payload(content)
-                encode_quopri(message)
-                self.mailer.smtp_send(to, str(message))
+                self.send_html_to_admin(subject, cgitb.pt_html())
                 # Now report the error to the user.
                 return self._(error_message)
             except: