[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ErrorReportingService - ErrorReportingService.py:1.10
Steve Alexander
steve@cat-box.net
Mon, 11 Nov 2002 09:15:44 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/ErrorReportingService
In directory cvs.zope.org:/tmp/cvs-serv4172/lib/python/Zope/App/OFS/Services/ErrorReportingService
Modified Files:
ErrorReportingService.py
Log Message:
ZopePublication is now responsible for swallowing and logging errors
raised while reporting errors in the ErrorReportingService.
This was previously the responsibility of the ErrorReportingService.
=== Zope3/lib/python/Zope/App/OFS/Services/ErrorReportingService/ErrorReportingService.py 1.9 => 1.10 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ErrorReportingService/ErrorReportingService.py:1.9 Mon Nov 11 08:13:07 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ErrorReportingService/ErrorReportingService.py Mon Nov 11 09:15:44 2002
@@ -17,12 +17,11 @@
$Id$
"""
-import sys
import time
from random import random
from thread import allocate_lock
from Persistence import Persistent
-from types import StringType, UnicodeType
+from types import StringTypes
from zLOG import LOG, ERROR
from Zope.Exceptions.ExceptionFormatter import format_exception
from Zope.ContextWrapper import ContextMethod
@@ -75,76 +74,77 @@
"""
now = time.time()
try:
- try:
- tb_text = None
- tb_html = None
+ tb_text = None
+ tb_html = None
- strtype = str(getattr(info[0], '__name__', info[0]))
- if strtype in self._ignored_exceptions:
- return
+ strtype = str(getattr(info[0], '__name__', info[0]))
+ if strtype in self._ignored_exceptions:
+ return
+
+ if not isinstance(info[2], StringTypes):
+ tb_text = ''.join(
+ format_exception(*info, **{'as_html': 0}))
+ tb_html = ''.join(
+ format_exception(*info, **{'as_html': 1}))
+ else:
+ tb_text = info[2]
- if not isinstance(info[2], StringType) and not isinstance(
- info[2], UnicodeType):
- tb_text = ''.join(
- format_exception(*info, **{'as_html': 0}))
- tb_html = ''.join(
- format_exception(*info, **{'as_html': 1}))
- else:
- tb_text = info[2]
-
- url = None
- username = None
- req_html = None
- if request:
- url = request.URL
- try:
- username = ','.join(request.user.getLogin(),
- request.user.getId(),
- request.user.getTitle(),
- request.user.getDescription()
- )
- # When there's an unauthorized access, request.user is
- # not set, so we get an AttributeError
- except AttributeError:
- pass
-
- req_html = ''.join(['%s : %s<br>' % item
- for item in request.items()])
+ url = None
+ username = None
+ req_html = None
+ if request:
+ url = request.URL
try:
- strv = str(info[1])
- # XXX bare except clause. Why is this here?
- except:
- strv = '<unprintable %s object>' % (
- str(type(info[1]).__name__)
- )
-
- log = self._getLog()
- entry_id = str(now) + str(random()) # Low chance of collision
-
- log.append({
- 'type': strtype,
- 'value': strv,
- 'time': time.ctime(now),
- 'id': entry_id,
- 'tb_text': tb_text,
- 'tb_html': tb_html,
- 'username': username,
- 'url': url,
- 'req_html': req_html,
- })
- cleanup_lock.acquire()
- try:
- if len(log) >= self.keep_entries:
- del log[:-self.keep_entries]
- finally:
- cleanup_lock.release()
- # XXX bare except clause. Why is this here?
+ username = ', '.join((request.user.getLogin(),
+ request.user.getId(),
+ request.user.getTitle(),
+ request.user.getDescription()
+ ))
+ # When there's an unauthorized access, request.user is
+ # not set, so we get an AttributeError
+ # XXX is this right? Surely request.user should be set!
+ except AttributeError:
+ pass
+
+ req_html = ''.join(['%s : %s<br>' % item
+ for item in request.items()])
+ try:
+ strv = str(info[1])
+ # A call to str(obj) could raise anything at all.
+ # We'll ignore these errors, and print something
+ # useful instead, but also log the error.
except:
- LOG('SiteError', ERROR, 'Error while logging',
- error=sys.exc_info())
- else:
- if self.copy_to_zlog:
- self._do_copy_to_zlog(now, strtype, str(url), info)
+ LOG('SiteError', ERROR,
+ 'Error in ErrorReportingService while getting a str '
+ 'representation of an object ',
+ error=sys.exc_info())
+ strv = '<unprintable %s object>' % (
+ str(type(info[1]).__name__)
+ )
+
+ log = self._getLog()
+ entry_id = str(now) + str(random()) # Low chance of collision
+
+ log.append({
+ 'type': strtype,
+ 'value': strv,
+ 'time': time.ctime(now),
+ 'id': entry_id,
+ 'tb_text': tb_text,
+ 'tb_html': tb_html,
+ 'username': username,
+ 'url': url,
+ 'req_html': req_html,
+ })
+ cleanup_lock.acquire()
+ try:
+ if len(log) >= self.keep_entries:
+ del log[:-self.keep_entries]
+ finally:
+ cleanup_lock.release()
+
+ if self.copy_to_zlog:
+ self._do_copy_to_zlog(now, strtype, str(url), info)
finally:
info = None
raising = ContextMethod(raising)