~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: James Westby
  • Date: 2008-05-15 17:24:12 UTC
  • mto: This revision was merged to the branch mainline in revision 3435.
  • Revision ID: jw+debian@jameswestby.net-20080515172412-elgcslbbj24tp9z5
Just print the exception, keeping the API of log_exception_quietly the same.

This also means that -Derror doesn't tell the user to report everything to
launchpad.

Show diffs side-by-side

added added

removed removed

Lines of Context:
321
321
    return pop_log_file(memento)
322
322
 
323
323
 
324
 
def log_exception_quietly(allow_debug=True):
 
324
def log_exception_quietly():
325
325
    """Log the last exception to the trace file only.
326
326
 
327
327
    Used for exceptions that occur internally and that may be 
328
328
    interesting to developers but not to users.  For example, 
329
329
    errors loading plugins.
330
330
    """
331
 
    exception_message = traceback.format_exc()
332
 
    mutter(exception_message)
333
 
    if 'error' in debug.debug_flags and allow_debug:
334
 
        sys.stderr.write(exception_message)
 
331
    mutter(traceback.format_exc())
335
332
 
336
333
 
337
334
def set_verbosity_level(level):
396
393
    """
397
394
    exc_type, exc_object, exc_tb = exc_info
398
395
    # Log the full traceback to ~/.bzr.log
399
 
    log_exception_quietly(allow_debug=False)
 
396
    log_exception_quietly()
400
397
    if (isinstance(exc_object, IOError)
401
398
        and getattr(exc_object, 'errno', None) == errno.EPIPE):
402
399
        err_file.write("bzr: broken pipe\n")
417
414
        return errors.EXIT_INTERNAL_ERROR
418
415
 
419
416
 
 
417
def print_exception(exc_info, err_file):
 
418
    exc_type, exc_object, exc_tb = exc_info
 
419
    err_file.write("bzr: ERROR: %s.%s: %s\n" % (
 
420
        exc_type.__module__, exc_type.__name__, exc_object))
 
421
    err_file.write('\n')
 
422
    traceback.print_exception(exc_type, exc_object, exc_tb, file=err_file)
 
423
 
 
424
 
420
425
# TODO: Should these be specially encoding the output?
421
426
def report_user_error(exc_info, err_file):
422
427
    """Report to err_file an error that's not an internal error.
424
429
    These don't get a traceback unless -Derror was given.
425
430
    """
426
431
    if 'error' in debug.debug_flags:
427
 
        report_bug(exc_info, err_file)
 
432
        print_exception(exc_info, err_file)
428
433
        return
429
434
    err_file.write("bzr: ERROR: %s\n" % (exc_info[1],))
430
435
 
431
436
 
432
437
def report_bug(exc_info, err_file):
433
438
    """Report an exception that probably indicates a bug in bzr"""
434
 
    exc_type, exc_object, exc_tb = exc_info
435
 
    err_file.write("bzr: ERROR: %s.%s: %s\n" % (
436
 
        exc_type.__module__, exc_type.__name__, exc_object))
437
 
    err_file.write('\n')
438
 
    traceback.print_exception(exc_type, exc_object, exc_tb, file=err_file)
 
439
    print_exception(exc_info, err_file)
439
440
    err_file.write('\n')
440
441
    err_file.write('bzr %s on python %s (%s)\n' % \
441
442
                       (bzrlib.__version__,