Merge lp:~stub/launchpad/oops into lp:launchpad

Proposed by Stuart Bishop
Status: Merged
Approved by: Stuart Bishop
Approved revision: 10004
Merged at revision: 14299
Proposed branch: lp:~stub/launchpad/oops
Merge into: lp:launchpad
Prerequisite: lp:~stub/launchpad/trivial
Diff against target: 59 lines (+31/-0)
2 files modified
lib/canonical/launchpad/webapp/errorlog.py (+10/-0)
lib/canonical/launchpad/webapp/tests/test_errorlog.py (+21/-0)
To merge this branch: bzr merge lp:~stub/launchpad/oops
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+82119@code.launchpad.net

Commit message

[r=rvb][no-qa] Attach a link to the previous OOPS generated in the request, if any.

Description of the change

Attach a link to the previous OOPS generated in the request, if any.

To post a comment you must log in.
Revision history for this message
Raphaël Badin (rvb) wrote :

Looks good.

One remark:

12 + if last_oopsid:

Not sure it's worth it but maybe it would be more safe/explicit to write: "if last_oopsid is not None:".

review: Approve
Revision history for this message
Stuart Bishop (stub) wrote :

Changed. Thanks!

lp:~stub/launchpad/oops updated
10005. By Stuart Bishop

Clarity

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/canonical/launchpad/webapp/errorlog.py'
--- lib/canonical/launchpad/webapp/errorlog.py 2011-11-08 14:05:08 +0000
+++ lib/canonical/launchpad/webapp/errorlog.py 2011-11-14 11:21:26 +0000
@@ -161,6 +161,14 @@
161_ignored_exceptions_for_unauthenticated_users = set(['Unauthorized'])161_ignored_exceptions_for_unauthenticated_users = set(['Unauthorized'])
162162
163163
164def attach_previous_oopsid(report, context):
165 """Add a link to the previous OOPS generated this request, if any."""
166 request = context.get('http_request')
167 last_oopsid = getattr(request, 'oopsid', None)
168 if last_oopsid is not None:
169 report['last_oops'] = last_oopsid
170
171
164def attach_http_request(report, context):172def attach_http_request(report, context):
165 """Add request metadata into the error report.173 """Add request metadata into the error report.
166174
@@ -312,6 +320,8 @@
312 # In the zope environment we track how long a script / http320 # In the zope environment we track how long a script / http
313 # request has been running for - this is useful data!321 # request has been running for - this is useful data!
314 self._oops_config.on_create.append(attach_adapter_duration)322 self._oops_config.on_create.append(attach_adapter_duration)
323 # Any previous OOPS reports generated this request.
324 self._oops_config.on_create.append(attach_previous_oopsid)
315325
316 def add_publisher(publisher):326 def add_publisher(publisher):
317 if publisher_adapter is not None:327 if publisher_adapter is not None:
318328
=== modified file 'lib/canonical/launchpad/webapp/tests/test_errorlog.py'
--- lib/canonical/launchpad/webapp/tests/test_errorlog.py 2011-10-27 05:40:56 +0000
+++ lib/canonical/launchpad/webapp/tests/test_errorlog.py 2011-11-14 11:21:26 +0000
@@ -184,6 +184,27 @@
184 # - a notify publisher184 # - a notify publisher
185 self.assertEqual(oops_config.publishers[2], notify_publisher)185 self.assertEqual(oops_config.publishers[2], notify_publisher)
186186
187 def test_multiple_raises_in_request(self):
188 """An OOPS links to the previous OOPS in the request, if any."""
189 utility = ErrorReportingUtility()
190 del utility._oops_config.publishers[0]
191
192 request = TestRequestWithPrincipal()
193 try:
194 raise ArbitraryException('foo')
195 except ArbitraryException:
196 report = utility.raising(sys.exc_info(), request)
197
198 self.assertFalse('last_oops' in report)
199 last_oopsid = request.oopsid
200 try:
201 raise ArbitraryException('foo')
202 except ArbitraryException:
203 report = utility.raising(sys.exc_info(), request)
204
205 self.assertTrue('last_oops' in report)
206 self.assertEqual(report['last_oops'], last_oopsid)
207
187 def test_raising_with_request(self):208 def test_raising_with_request(self):
188 """Test ErrorReportingUtility.raising() with a request"""209 """Test ErrorReportingUtility.raising() with a request"""
189 utility = ErrorReportingUtility()210 utility = ErrorReportingUtility()