/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/trace.py

  • Committer: Robert Collins
  • Date: 2008-07-01 03:38:35 UTC
  • mfrom: (3514 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3515.
  • Revision ID: robertc@robertcollins.net-20080701033835-dwbt0f0x3vmf5atr
Merge bzr.dev, fixing minor skew.

Show diffs side-by-side

added added

removed removed

Lines of Context:
168
168
    :param args: A list of substitution variables.
169
169
    """
170
170
    outf = StringIO()
171
 
    traceback.print_stack(limit=stacklevel + 1, file=outf)
 
171
    if stacklevel is None:
 
172
        limit = None
 
173
    else:
 
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,)))
401
405
    elif isinstance(exc_object, KeyboardInterrupt):
402
406
        err_file.write("bzr: interrupted\n")
403
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
404
413
    elif not getattr(exc_object, 'internal_error', True):
405
414
        report_user_error(exc_info, err_file)
406
415
        return errors.EXIT_ERROR
423
432
 
424
433
 
425
434
# TODO: Should these be specially encoding the output?
426
 
def report_user_error(exc_info, err_file):
 
435
def report_user_error(exc_info, err_file, advice=None):
427
436
    """Report to err_file an error that's not an internal error.
428
437
 
429
438
    These don't get a traceback unless -Derror was given.
 
439
 
 
440
    :param exc_info: 3-tuple from sys.exc_info()
 
441
    :param advice: Extra advice to the user to be printed following the
 
442
        exception.
430
443
    """
431
444
    if 'error' in debug.debug_flags:
432
445
        print_exception(exc_info, err_file)
433
446
        return
434
447
    err_file.write("bzr: ERROR: %s\n" % (exc_info[1],))
 
448
    if advice:
 
449
        err_file.write("%s\n" % (advice,))
435
450
 
436
451
 
437
452
def report_bug(exc_info, err_file):