Merge lp:~mdz/apport/681574-improve-python-titles into lp:~apport-hackers/apport/trunk

Proposed by Matt Zimmerman
Status: Merged
Merged at revision: 1806
Proposed branch: lp:~mdz/apport/681574-improve-python-titles
Merge into: lp:~apport-hackers/apport/trunk
Diff against target: 96 lines (+55/-7)
1 file modified
apport/report.py (+55/-7)
To merge this branch: bzr merge lp:~mdz/apport/681574-improve-python-titles
Reviewer Review Type Date Requested Status
Apport upstream developers Pending
Review via email: mp+41900@code.launchpad.net

Description of the change

  Improve standard titles for Python bugs.

  If the crash occurs at the top level in the main program:
  "foo crashed with ImportError"

  If the crash occurs at the top level in a module:
  "foo crashed with ImportError in /usr/share/foo/plugin.py"

  Also include the exception text in the report, e.g.:
  "foo crashed with ImportError: No module named nonexistent"

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'apport/report.py'
2--- apport/report.py 2010-06-01 08:09:39 +0000
3+++ apport/report.py 2010-11-25 20:57:17 +0000
4@@ -880,22 +880,46 @@
5 os.path.basename(self['ExecutablePath']),
6 trace[0])
7
8- trace_re = re.compile('^\s*File.* in (.+)$')
9+ trace_re = re.compile('^\s*File\s*"(\S+)".* in (.+)$')
10 i = len(trace)-1
11 function = 'unknown'
12 while i >= 0:
13 m = trace_re.match(trace[i])
14 if m:
15- function = m.group(1)
16+ module_path = m.group(1)
17+ function = m.group(2)
18 break
19 i -= 1
20
21- return '%s crashed with %s in %s()' % (
22- os.path.basename(self['ExecutablePath']),
23- trace[-1].split(':')[0],
24- function
25+ path = os.path.basename(self['ExecutablePath'])
26+ last_line = trace[-1]
27+ exception = last_line.split(':')[0]
28+ m = re.match('^%s: (.+)$' % exception, last_line)
29+ if m:
30+ message = m.group(1)
31+ else:
32+ message = None
33+
34+ if function == '<module>':
35+ if module_path == self['ExecutablePath']:
36+ context = '__main__'
37+ else:
38+ # Maybe use os.path.basename?
39+ context = module_path
40+ else:
41+ context = '%s()' % function
42+
43+ title = '%s crashed with %s in %s' % (
44+ path,
45+ exception,
46+ context
47 )
48
49+ if message:
50+ title += ': %s' % message
51+
52+ return title
53+
54 # package problem
55 if self.get('ProblemType') == 'Package' and \
56 self.has_key('Package'):
57@@ -2066,7 +2090,7 @@
58 subprocess.call(['pgrep', '-x',
59 NameError: global name 'subprocess' is not defined'''
60 self.assertEqual(report.standard_title(),
61- 'apport-gtk crashed with NameError in ui_present_crash()')
62+ "apport-gtk crashed with NameError in ui_present_crash(): global name 'subprocess' is not defined")
63
64 # slightly weird Python crash
65 report = Report()
66@@ -2100,6 +2124,30 @@
67 self.assert_(t.startswith('apport-gtk crashed with'))
68 self.assert_(t.endswith('setup_chooser()'))
69
70+ # Python crash at top level in module
71+ report = Report()
72+ report['ExecutablePath'] = '/usr/bin/gnome-about'
73+ report['Traceback'] = '''Traceback (most recent call last):
74+ File "/usr/bin/gnome-about", line 30, in <module>
75+ import pygtk
76+ File "/usr/lib/pymodules/python2.6/pygtk.py", line 28, in <module>
77+ import nonexistent
78+ImportError: No module named nonexistent
79+'''
80+ self.assertEqual(report.standard_title(),
81+ "gnome-about crashed with ImportError in /usr/lib/pymodules/python2.6/pygtk.py: No module named nonexistent")
82+
83+ # Python crash at top level in main program
84+ report = Report()
85+ report['ExecutablePath'] = '/usr/bin/dcut'
86+ report['Traceback'] = '''Traceback (most recent call last):
87+ File "/usr/bin/dcut", line 28, in <module>
88+ import nonexistent
89+ImportError: No module named nonexistent
90+'''
91+ self.assertEqual(report.standard_title(),
92+ "dcut crashed with ImportError in __main__: No module named nonexistent")
93+
94 # package install problem
95 report = Report('Package')
96 report['Package'] = 'bash'

Subscribers

People subscribed via source and target branches