168
168
:param args: A list of substitution variables.
170
170
outf = StringIO()
171
traceback.print_stack(limit=stacklevel + 1, file=outf)
171
if stacklevel is None:
174
limit = stacklevel + 1
175
traceback.print_stack(limit=limit, file=outf)
172
176
formatted_lines = outf.getvalue().splitlines()
173
177
formatted_stack = '\n'.join(formatted_lines[:-2])
174
178
mutter(fmt + "\nCalled from:\n%s", *(args + (formatted_stack,)))
295
299
This flushes, but does not close the trace file.
297
301
Takes the memento returned from _push_log_file."""
298
assert magic == 'log_memento'
299
302
global _trace_file
300
303
_trace_file = old_trace_file
301
304
bzr_logger = logging.getLogger('bzr')
402
405
elif isinstance(exc_object, KeyboardInterrupt):
403
406
err_file.write("bzr: interrupted\n")
404
407
return errors.EXIT_ERROR
408
elif isinstance(exc_object, ImportError) \
409
and str(exc_object).startswith("No module named "):
410
report_user_error(exc_info, err_file,
411
'You may need to install this Python library separately.')
412
return errors.EXIT_ERROR
405
413
elif not getattr(exc_object, 'internal_error', True):
406
414
report_user_error(exc_info, err_file)
407
415
return errors.EXIT_ERROR
415
423
return errors.EXIT_INTERNAL_ERROR
426
def print_exception(exc_info, err_file):
427
exc_type, exc_object, exc_tb = exc_info
428
err_file.write("bzr: ERROR: %s.%s: %s\n" % (
429
exc_type.__module__, exc_type.__name__, exc_object))
431
traceback.print_exception(exc_type, exc_object, exc_tb, file=err_file)
418
434
# TODO: Should these be specially encoding the output?
419
def report_user_error(exc_info, err_file):
435
def report_user_error(exc_info, err_file, advice=None):
420
436
"""Report to err_file an error that's not an internal error.
422
438
These don't get a traceback unless -Derror was given.
440
:param exc_info: 3-tuple from sys.exc_info()
441
:param advice: Extra advice to the user to be printed following the
424
444
if 'error' in debug.debug_flags:
425
report_bug(exc_info, err_file)
445
print_exception(exc_info, err_file)
427
447
err_file.write("bzr: ERROR: %s\n" % (exc_info[1],))
449
err_file.write("%s\n" % (advice,))
430
452
def report_bug(exc_info, err_file):
431
453
"""Report an exception that probably indicates a bug in bzr"""
432
exc_type, exc_object, exc_tb = exc_info
433
err_file.write("bzr: ERROR: %s.%s: %s\n" % (
434
exc_type.__module__, exc_type.__name__, exc_object))
436
traceback.print_exception(exc_type, exc_object, exc_tb, file=err_file)
454
print_exception(exc_info, err_file)
437
455
err_file.write('\n')
438
456
err_file.write('bzr %s on python %s (%s)\n' % \
439
457
(bzrlib.__version__,