/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/crash.py

  • Committer: Martin Pool
  • Date: 2009-08-20 04:45:48 UTC
  • mto: This revision was merged to the branch mainline in revision 4632.
  • Revision ID: mbp@sourcefrog.net-20090820044548-r1jgiv8golcl4auh
further tweaks to and tests of bzr apport reporting

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import pprint
26
26
import sys
27
27
import time
 
28
from StringIO import StringIO
28
29
 
29
30
import bzrlib
30
31
from bzrlib import (
44
45
        except Exception, e:
45
46
            # this should only happen if apport is installed but it didn't
46
47
            # work, eg because of an io error writing the crash file
47
 
            sys.stderr.write("failed to report crash using apport: %r"  % e)
 
48
            sys.stderr.write("bzr: failed to report crash using apport:\n "
 
49
                "    %r\n" % e)
48
50
            pass
49
51
    report_bug_legacy(exc_info, stderr)
50
52
 
63
65
            osutils.get_user_encoding(), sys.getfilesystemencoding(),
64
66
            os.environ.get('LANG')))
65
67
    err_file.write("plugins:\n")
66
 
    for name, a_plugin in sorted(plugin.plugins().items()):
67
 
        err_file.write("  %-20s %s [%s]\n" %
68
 
            (name, a_plugin.path(), a_plugin.__version__))
 
68
    err_file.write(_format_plugin_list())
69
69
    err_file.write(
 
70
        "\n\n"
70
71
        "*** Bazaar has encountered an internal error.  This probably indicates a\n"
71
 
        "*** bug in Bazaar.  You can help us fix it by filing a bug report at\n"
72
 
        "***     https://bugs.launchpad.net/bzr/+filebug\n"
73
 
        "*** including this traceback and a description of the problem.\n"
 
72
        "    bug in Bazaar.  You can help us fix it by filing a bug report at\n"
 
73
        "        https://bugs.launchpad.net/bzr/+filebug\n"
 
74
        "    including this traceback and a description of the problem.\n"
74
75
        )
75
76
 
76
77
 
90
91
 
91
92
    crash_file = _open_crash_file()
92
93
    try:
93
 
        _write_apport_report_to_file(crash_file)
 
94
        _write_apport_report_to_file(exc_info, crash_file)
94
95
    finally:
95
96
        crash_file.close()
96
97
 
97
98
    stderr.write("bzr: ERROR: %s.%s: %s\n" 
98
99
        "\n"
99
100
        "*** Bazaar has encountered an internal error.  This probably indicates a\n"
100
 
        "*** bug in Bazaar.  You can help us fix it by filing a bug report at\n"
101
 
        "***     https://bugs.launchpad.net/bzr/+filebug\n"
102
 
        "*** attaching the crash file\n"
103
 
        "***     %s\n"
104
 
        "*** and including a description of the problem.\n"
 
101
        "    bug in Bazaar.  You can help us fix it by filing a bug report at\n"
 
102
        "        https://bugs.launchpad.net/bzr/+filebug\n"
 
103
        "    attaching the crash file\n"
 
104
        "        %s\n"
 
105
        "    and including a description of the problem.\n"
 
106
        "\n"
 
107
        "    The crash file is plain text and you can inspect or edit it to remove\n"
 
108
        "    private information.\n"
105
109
        % (exc_info[0].__module__, exc_info[0].__name__, exc_info[1],
106
110
           crash_file.name))
107
111
    return True
109
113
 
110
114
def _write_apport_report_to_file(exc_info, crash_file):
111
115
    import platform
 
116
    import traceback
112
117
    from apport.report import Report
 
118
 
 
119
    exc_type, exc_object, exc_tb = exc_info
 
120
 
113
121
    pr = Report()
114
122
    # add_proc_info gives you the memory map of the process: this seems rarely
115
123
    # useful for Bazaar and it does make the report harder to scan, though it
116
124
    # does tell you what binary modules are loaded.
117
125
    # pr.add_proc_info()
118
126
    pr.add_user_info()
 
127
    pr['CommandLine'] = pprint.pformat(sys.argv)
119
128
    pr['BzrVersion'] = bzrlib.__version__
120
129
    pr['PythonVersion'] = bzrlib._format_version_tuple(sys.version_info)
121
130
    pr['Platform'] = platform.platform(aliased=1)
124
133
    pr['Locale'] = os.environ.get('LANG')
125
134
    pr['BzrPlugins'] = _format_plugin_list()
126
135
    pr['PythonLoadedModules'] = _format_module_list()
 
136
    pr['BzrDebugFlags'] = pprint.pformat(debug.debug_flags)
 
137
 
 
138
    tb_file = StringIO()
 
139
    traceback.print_exception(exc_type, exc_object, exc_tb, file=tb_file)
 
140
    pr['Traceback'] = tb_file.getvalue()
 
141
 
127
142
    pr.write(crash_file)
128
143
 
129
144