From: stefan Date: Fri, 9 Oct 2009 13:13:32 +0000 (+0000) Subject: Improve error reporting. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=802f6a7246e183054e684b7d1710b0705cf6e35b;p=roundup.git Improve error reporting. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4368 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/roundup/cgi/cgitb.py b/roundup/cgi/cgitb.py index 50ea475..b89cb46 100644 --- a/roundup/cgi/cgitb.py +++ b/roundup/cgi/cgitb.py @@ -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('%s%s'%(k, cgi.escape(repr(v)))) return '\n'.join(l) diff --git a/roundup/cgi/client.py b/roundup/cgi/client.py index 13db91c..ea973f3 100644 --- a/roundup/cgi/client.py +++ b/roundup/cgi/client.py @@ -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 = ("

Traceback

" + + cgitb.html(i18n=self.translator) + + ("

Environment Variables

%s
" + % 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: