314
315
def report_exception(exc_info, err_file):
316
"""Report an exception to err_file (typically stderr) and to .bzr.log.
318
This will show either a full traceback or a short message as appropriate.
320
:return: The appropriate exit code for this error.
315
322
exc_type, exc_object, exc_tb = exc_info
316
323
# Log the full traceback to ~/.bzr.log
317
324
log_exception_quietly()
318
325
if (isinstance(exc_object, IOError)
319
326
and getattr(exc_object, 'errno', None) == errno.EPIPE):
320
327
print >>err_file, "bzr: broken pipe"
328
return errors.EXIT_ERROR
321
329
elif isinstance(exc_object, KeyboardInterrupt):
322
330
print >>err_file, "bzr: interrupted"
331
return errors.EXIT_ERROR
323
332
elif not getattr(exc_object, 'internal_error', True):
324
333
report_user_error(exc_info, err_file)
334
return errors.EXIT_ERROR
325
335
elif isinstance(exc_object, (OSError, IOError)):
326
336
# Might be nice to catch all of these and show them as something more
327
337
# specific, but there are too many cases at the moment.
328
338
report_user_error(exc_info, err_file)
339
return errors.EXIT_ERROR
330
341
report_bug(exc_info, err_file)
342
return errors.EXIT_INTERNAL_ERROR
333
345
# TODO: Should these be specially encoding the output?