~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/crash.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009-2011 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
 
17
18
"""Handling and reporting crashes.
18
19
 
19
20
A crash is an exception propagated up almost to the top level of Bazaar.
36
37
-Dno_apport.
37
38
"""
38
39
 
39
 
from __future__ import absolute_import
40
 
 
41
40
# for interactive testing, try the 'bzr assert-fail' command 
42
41
# or see http://code.launchpad.net/~mbp/bzr/bzr-fail
43
42
#
71
70
            return
72
71
    except ImportError, e:
73
72
        trace.mutter("couldn't find apport bug-reporting library: %s" % e)
 
73
        pass
74
74
    except Exception, e:
75
75
        # this should only happen if apport is installed but it didn't
76
76
        # work, eg because of an io error writing the crash file
77
 
        trace.mutter("bzr: failed to report crash using apport: %r" % e)
78
 
        trace.log_exception_quietly()
 
77
        stderr.write("bzr: failed to report crash using apport:\n "
 
78
            "    %r\n" % e)
 
79
        pass
79
80
    return report_bug_legacy(exc_info, stderr)
80
81
 
81
82
 
83
84
    """Report a bug by just printing a message to the user."""
84
85
    trace.print_exception(exc_info, err_file)
85
86
    err_file.write('\n')
86
 
    import textwrap
87
 
    def print_wrapped(l):
88
 
        err_file.write(textwrap.fill(l,
89
 
            width=78, subsequent_indent='    ') + '\n')
90
 
    print_wrapped('bzr %s on python %s (%s)\n' % \
91
 
        (bzrlib.__version__,
92
 
        bzrlib._format_version_tuple(sys.version_info),
93
 
        platform.platform(aliased=1)))
94
 
    print_wrapped('arguments: %r\n' % sys.argv)
95
 
    print_wrapped(textwrap.fill(
96
 
        'plugins: ' + plugin.format_concise_plugin_list(),
97
 
        width=78,
98
 
        subsequent_indent='    ',
99
 
        ) + '\n')
100
 
    print_wrapped(
 
87
    err_file.write('bzr %s on python %s (%s)\n' % \
 
88
                       (bzrlib.__version__,
 
89
                        bzrlib._format_version_tuple(sys.version_info),
 
90
                        platform.platform(aliased=1)))
 
91
    err_file.write('arguments: %r\n' % sys.argv)
 
92
    err_file.write(
101
93
        'encoding: %r, fsenc: %r, lang: %r\n' % (
102
94
            osutils.get_user_encoding(), sys.getfilesystemencoding(),
103
95
            os.environ.get('LANG')))
104
 
    # We used to show all the plugins here, but it's too verbose.
 
96
    err_file.write("plugins:\n")
 
97
    err_file.write(_format_plugin_list())
105
98
    err_file.write(
106
 
        "\n"
 
99
        "\n\n"
107
100
        "*** Bazaar has encountered an internal error.  This probably indicates a\n"
108
101
        "    bug in Bazaar.  You can help us fix it by filing a bug report at\n"
109
102
        "        https://bugs.launchpad.net/bzr/+filebug\n"
119
112
    # this function is based on apport_package_hook.py, but omitting some of the
120
113
    # Ubuntu-specific policy about what to report and when
121
114
 
122
 
    # This import is apparently not used, but we're doing it so that if the
123
 
    # import fails, the exception will be caught at a higher level and we'll
124
 
    # report the error by other means.
 
115
    # if the import fails, the exception will be caught at a higher level and
 
116
    # we'll report the error by other means
125
117
    import apport
126
118
 
127
119
    crash_filename = _write_apport_report_to_file(exc_info)
151
143
    exc_type, exc_object, exc_tb = exc_info
152
144
 
153
145
    pr = Report()
154
 
    # add_proc_info sets the ExecutablePath, InterpreterPath, etc.
 
146
    # add_proc_info gives you the memory map of the process, which is not so
 
147
    # useful for Bazaar but does tell you what binary libraries are loaded.
 
148
    # More importantly it sets the ExecutablePath, InterpreterPath, etc.
155
149
    pr.add_proc_info()
156
 
    # It also adds ProcMaps which for us is rarely useful and mostly noise, so
157
 
    # let's remove it.
158
 
    del pr['ProcMaps']
159
150
    pr.add_user_info()
160
151
 
161
152
    # Package and SourcePackage are needed so that apport will report about even
170
161
    pr['Platform'] = platform.platform(aliased=1)
171
162
    pr['UserEncoding'] = osutils.get_user_encoding()
172
163
    pr['FileSystemEncoding'] = sys.getfilesystemencoding()
173
 
    pr['Locale'] = os.environ.get('LANG', 'C')
 
164
    pr['Locale'] = os.environ.get('LANG')
174
165
    pr['BzrPlugins'] = _format_plugin_list()
175
166
    pr['PythonLoadedModules'] = _format_module_list()
176
167
    pr['BzrDebugFlags'] = pprint.pformat(debug.debug_flags)
259
250
        os.open(filename, 
260
251
            os.O_WRONLY|os.O_CREAT|os.O_EXCL,
261
252
            0600),
262
 
        'wb')
 
253
        'w')
263
254
 
264
255
 
265
256
def _format_plugin_list():
266
 
    return ''.join(plugin.describe_plugins(show_paths=True))
 
257
    plugin_lines = []
 
258
    for name, a_plugin in sorted(plugin.plugins().items()):
 
259
        plugin_lines.append("  %-20s %s [%s]" %
 
260
            (name, a_plugin.path(), a_plugin.__version__))
 
261
    return '\n'.join(plugin_lines)
267
262
 
268
263
 
269
264
def _format_module_list():