Merge lp:~lifeless/python-oops-tools/bug-890001 into lp:python-oops-tools

Proposed by Robert Collins
Status: Merged
Approved by: Robert Collins
Approved revision: 15
Merged at revision: 15
Proposed branch: lp:~lifeless/python-oops-tools/bug-890001
Merge into: lp:python-oops-tools
Diff against target: 83 lines (+54/-0)
3 files modified
src/oopstools/NEWS.txt (+3/-0)
src/oopstools/oops/models.py (+8/-0)
src/oopstools/oops/test/test_dboopsloader.py (+43/-0)
To merge this branch: bzr merge lp:~lifeless/python-oops-tools/bug-890001
Reviewer Review Type Date Requested Status
Steve Kowalik (community) code Approve
Review via email: mp+82334@code.launchpad.net

Commit message

Handle a crash in oops-tools when a bad report has been generated by LP.

Description of the change

Handle a crash in oops-tools when a bad report has been generated by LP. This replaces a monkey patch we're currently running.

To post a comment you must log in.
Revision history for this message
Steve Kowalik (stevenk) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/oopstools/NEWS.txt'
2--- src/oopstools/NEWS.txt 2011-11-11 04:00:56 +0000
3+++ src/oopstools/NEWS.txt 2011-11-16 01:33:23 +0000
4@@ -18,6 +18,9 @@
5 * The req_vars variable in OOPS reports may now be a dict.
6 (Robert Collins, #888866)
7
8+* Corrupt timeline objects are handled more gracefully if they are not a list,
9+ or the list rows are too short or too long. (Robert Collins, #890001)
10+
11 0.6.1
12 =====
13
14
15=== modified file 'src/oopstools/oops/models.py'
16--- src/oopstools/oops/models.py 2011-11-11 04:00:56 +0000
17+++ src/oopstools/oops/models.py 2011-11-16 01:33:23 +0000
18@@ -345,6 +345,14 @@
19 elif key == 'HTTP_USER_AGENT':
20 data['user_agent'] = conform(value, 200)
21 statements = oops.get('timeline') or []
22+ # Sanity check/coerce the statements into what we expect.
23+ # Must be a list:
24+ if not isinstance(statements, list):
25+ statements = [(0, 0, 'badtimeline', str(statements))]
26+ else:
27+ filler = (0, 0, 'unknown', 'unknown')
28+ for row, action in enumerate(statements):
29+ statements[row] = tuple(action[:4]) + filler[len(action):]
30 duration = oops.get('duration')
31 if duration is not None:
32 total_time = int(duration * 1000)
33
34=== modified file 'src/oopstools/oops/test/test_dboopsloader.py'
35--- src/oopstools/oops/test/test_dboopsloader.py 2011-11-11 04:00:56 +0000
36+++ src/oopstools/oops/test/test_dboopsloader.py 2011-11-16 01:33:23 +0000
37@@ -186,3 +186,46 @@
38 }
39 oops = parsed_oops_to_model_oops(report, 'bug-888866')
40 self.assertEqual('myuseragent', oops.user_agent)
41+
42+ def test_nonlist_timeline(self):
43+ # A timeline that is nonzero and not a list is turned into a one-entry
44+ # timeline starting when the oops starts with no duration and category
45+ # badtimeline.
46+ report = {
47+ 'id': 'bug-890001-1',
48+ 'timeline': 'a'
49+ }
50+ oops = parsed_oops_to_model_oops(report, 'bug-890001-1')
51+ self.assertEqual([(0, 0, 'badtimeline', 'a')], oops.statements)
52+
53+ def test_short_timeline_row(self):
54+ # A timeline row that is short is padded with 'unknown' or 0's.
55+ report = {
56+ 'id': 'bug-890001-2',
57+ 'timeline': [
58+ (),
59+ (1,),
60+ (1, 2,),
61+ (1, 2, 'foo'),
62+ ],
63+ }
64+ oops = parsed_oops_to_model_oops(report, 'bug-890001-2')
65+ self.assertEqual([
66+ (0, 0, 'unknown', 'unknown'),
67+ (1, 0, 'unknown', 'unknown'),
68+ (1, 2, 'unknown', 'unknown'),
69+ (1, 2, 'foo', 'unknown'),
70+ ], oops.statements)
71+
72+ def test_long_timeline_row(self):
73+ # A timeline row that is long is truncated.
74+ report = {
75+ 'id': 'bug-890001-3',
76+ 'timeline': [
77+ (1, 2, 'foo', 'bar', 'baz'),
78+ ],
79+ }
80+ oops = parsed_oops_to_model_oops(report, 'bug-890001-3')
81+ self.assertEqual([
82+ (1, 2, 'foo', 'bar'),
83+ ], oops.statements)

Subscribers

People subscribed via source and target branches

to all changes: