← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~lifeless/python-oops-twisted/defensive-and-logs into lp:python-oops-twisted

 

Robert Collins has proposed merging lp:~lifeless/python-oops-twisted/defensive-and-logs into lp:python-oops-twisted.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #859545 in python-oops-twisted: "Fallback code corrupts the output"
  https://bugs.launchpad.net/python-oops-twisted/+bug/859545
  Bug #860490 in python-oops-twisted: "oops reports with no type/value crash the fallback reporting code"
  https://bugs.launchpad.net/python-oops-twisted/+bug/860490

For more details, see:
https://code.launchpad.net/~lifeless/python-oops-twisted/defensive-and-logs/+merge/77295

Fix two more bugs in oops-twisted - meet the twisted protocol for eventDict['message'], and don't assume that the oops Config will generate oopses with exception type and value set.
-- 
https://code.launchpad.net/~lifeless/python-oops-twisted/defensive-and-logs/+merge/77295
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~lifeless/python-oops-twisted/defensive-and-logs into lp:python-oops-twisted.
=== modified file 'NEWS'
--- NEWS	2011-09-27 07:07:19 +0000
+++ NEWS	2011-09-28 09:10:27 +0000
@@ -6,6 +6,18 @@
 NEXT
 ----
 
+0.0.3
+-----
+
+* Generate fallback log events with [message] as twisted's core does not handle
+  a simple message itself. (Robert Collins, #859545)
+
+* Handle pathological OOPSes - e.g. if a user removes the default on_create
+  hooks. (Robert Collins, #860490)
+
+0.0.2
+-----
+
 * Bump dependency on oops to 0.0.7 to permit buildout to work.
   (Robert Collins, #859566)
 

=== modified file 'oops_twisted/__init__.py'
--- oops_twisted/__init__.py	2011-09-27 07:11:58 +0000
+++ oops_twisted/__init__.py	2011-09-28 09:10:27 +0000
@@ -97,7 +97,7 @@
 # established at this point, and setup.py will use a version of next-$(revno).
 # If the releaselevel is 'final', then the tarball will be major.minor.micro.
 # Otherwise it is major.minor.micro~$(revno).
-__version__ = (0, 0, 2, 'beta', 0)
+__version__ = (0, 0, 3, 'beta', 0)
 
 __all__ = [
     'Config',

=== modified file 'oops_twisted/log.py'
--- oops_twisted/log.py	2011-09-27 07:07:19 +0000
+++ oops_twisted/log.py	2011-09-28 09:10:27 +0000
@@ -76,7 +76,8 @@
         if ids:
             event['isError'] = False
             event.pop('failure', None)
-            event['message'] = "Logged OOPS id %s: %s: %s" % (
-                report['id'], report['type'], report['value']) 
+            event['message'] = ["Logged OOPS id %s: %s: %s" % (
+                report['id'], report.get('type', 'No exception type'),
+                report.get('value', 'No exception value'))]
         if ids is not None:
             self.fallback(event)

=== modified file 'oops_twisted/tests/test_log.py'
--- oops_twisted/tests/test_log.py	2011-09-27 07:07:19 +0000
+++ oops_twisted/tests/test_log.py	2011-09-28 09:10:27 +0000
@@ -125,7 +125,39 @@
         expected_event = {
             'isError': False,
             'time': now,
-            'message': expected_message,
+            'message': [expected_message],
+            'why': 'testing',
+            }
+        d.addCallback(lambda result: self.assertEqual([expected_event], calls))
+        return d
+
+    def test_failure_fallback_no_exception_info(self):
+        # An oops being logged without an exception type/value still formats
+        # and forwards to the fall back successfully.
+        calls = []
+        def fallback(eventDict):
+            calls.append(eventDict)
+        def assignid(report):
+            return defer.succeed(22)
+        config = Config()
+        # Remove the default hooks to get a totally minimal report - users
+        # might do this themselves.
+        del config.on_create[:]
+        config.publishers.append(assignid)
+        observer = OOPSObserver(config, fallback=fallback)
+        now = time.time()
+        try:
+            raise ValueError('exception message')
+        except ValueError:
+            event = dict(isError=True, message=None, time=now,
+                failure=failure.Failure(), why='testing')
+        report, d = observer.emit(event)
+        expected_message = "Logged OOPS id %s: %s: %s" % (
+            22, "No exception type", "No exception value")
+        expected_event = {
+            'isError': False,
+            'time': now,
+            'message': [expected_message],
             'why': 'testing',
             }
         d.addCallback(lambda result: self.assertEqual([expected_event], calls))

=== modified file 'setup.py'
--- setup.py	2011-09-27 07:11:58 +0000
+++ setup.py	2011-09-28 09:10:27 +0000
@@ -23,7 +23,7 @@
         os.path.join(os.path.dirname(__file__), 'README'), 'rb').read()
 
 setup(name="oops_twisted",
-      version="0.0.2",
+      version="0.0.3",
       description=\
               "Translate twisted error logs into OOPS error reports.",
       long_description=description,