272
274
print >>err_file, "bzr: broken pipe"
273
275
elif isinstance(exc_object, KeyboardInterrupt):
274
276
print >>err_file, "bzr: interrupted"
275
elif getattr(exc_object, 'is_user_error', False):
277
elif not getattr(exc_object, 'internal_error', True):
276
278
report_user_error(exc_info, err_file)
277
279
elif isinstance(exc_object, (OSError, IOError)):
278
280
# Might be nice to catch all of these and show them as something more
279
281
# specific, but there are too many cases at the moment.
280
282
report_user_error(exc_info, err_file)
282
report_bug(exc_info, err_file)
284
return report_bug(exc_info, err_file)
285
287
# TODO: Should these be specially encoding the output?
297
299
def report_bug(exc_info, err_file):
298
300
"""Report an exception that probably indicates a bug in bzr"""
301
# local import because its only needed here, and this is not a loop.
303
# local import because the other functions do it too.
305
# local import due to circular dependency
309
# detect apport presence.
311
import problem_report
313
# not present, dont use it.
316
# policy disabled, or not present, use the old ui.
317
return _old_report_bug(exc_info, err_file)
319
exc_type, exc_object, exc_tb = exc_info
321
"bzr: ERROR: %s.%s: %s\n" % (
322
exc_type.__module__, exc_type.__name__, exc_object)
324
report = problem_report.ProblemReport()
325
report_file, report_filename = tempfile.mkstemp(
326
suffix='.txt', prefix='bzr-crash-', dir='/tmp')
327
python_report_file = os.fdopen(report_file, 'w')
329
report['CommandLine'] = ' '.join(sys.argv)
330
# assume we are packaged as bzr.
331
apport_utils.report_add_package_info(report, 'bzr')
332
report['BzrPlugins'] = ' '.join(bzrlib.plugin.all_plugins())
334
traceback.print_exception(exc_type, exc_object, exc_tb, file=tb_file)
335
report['Traceback'] = tb_file.getvalue()
336
apport_utils.report_add_os_info(report)
337
report.write(python_report_file)
338
# give the user a pretty output.
341
'This is an unexpected error within bzr and we would appreciate a bug report.\n'
343
'bzr has written a crash report file that will assist our debugging of this\n'
346
'This is a plain text file, whose contents you can check if you have privacy\n'
347
'concerns. We gather the package data about bzr, your command line, plugins\n'
348
'And the backtrace from within bzr. If you had a password in the URL you\n'
349
'provided to bzr, you should edit that file to remove the password.\n'
351
'** To file a bug for this please visit our bugtracker at the URL \n'
352
'"https://launchpad.net/products/bzr/+filebug" and report a bug describing\n'
353
'what you were attempting and attach the bzr-crash file mentioned above.\n'
354
'Alternatively you can email bazaar-ng@lists.canonical.com with the same\n'
355
'description and attach the bzr-crash file to the email.\n' %
359
python_report_file.close()
360
return report, report_filename
362
def _old_report_bug(exc_info, err_file):
363
"""Write a synopsis of an exception that is probably a bug to err_file."""
300
365
exc_type, exc_object, exc_tb = exc_info
301
366
print >>err_file, "bzr: ERROR: %s.%s: %s" % (