~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Martin Pool
  • Date: 2005-04-15 03:28:29 UTC
  • Revision ID: mbp@sourcefrog.net-20050415032829-4fcd42b8ff201ed9
- better reporting of errors
- handle assertions specially

Show diffs side-by-side

added added

removed removed

Lines of Context:
1013
1013
 
1014
1014
 
1015
1015
 
 
1016
def _report_exception(e, summary):
 
1017
    import traceback
 
1018
    log_error('bzr: ' + summary)
 
1019
    bzrlib.trace.log_exception(e)
 
1020
    tb = sys.exc_info()[2]
 
1021
    exinfo = traceback.extract_tb(tb, 1)
 
1022
    if exinfo:
 
1023
        sys.stderr.write('  at %s:%d in %s()\n' % exinfo[0][:3])
 
1024
    sys.stderr.write('  see ~/.bzr.log for debug information\n')
 
1025
 
 
1026
 
 
1027
def cmd_assert_fail():
 
1028
    assert False
 
1029
 
 
1030
 
1016
1031
def main(argv):
1017
1032
    bzrlib.trace.create_tracefile(argv)
1018
1033
 
1021
1036
            ret = run_bzr(argv)
1022
1037
            return ret
1023
1038
        except BzrError, e:
1024
 
            log_error('bzr: error: ' + e.args[0])
 
1039
            _report_exception(e, 'error: ' + e.args[0])
1025
1040
            if len(e.args) > 1:
1026
1041
                for h in e.args[1]:
 
1042
                    # some explanation or hints
1027
1043
                    log_error('  ' + h)
1028
 
            bzrlib.trace.log_exception(e)
1029
 
            sys.stderr.write('(see ~/.bzr.log for debug information)\n')
1030
1044
            return 1
 
1045
        except AssertionError, e:
 
1046
            msg = 'assertion failed'
 
1047
            if str(e):
 
1048
                msg += ': ' + str(e)
 
1049
            _report_exception(e, msg)
1031
1050
        except Exception, e:
1032
 
            log_error('bzr: exception: %s' % str(e).rstrip('\n'))
1033
 
            sys.stderr.write('(see $HOME/.bzr.log for debug information)\n')
1034
 
            bzrlib.trace.log_exception(e)
 
1051
            _report_exception(e, 'exception: %s' % str(e).rstrip('\n'))
1035
1052
            return 1
1036
1053
    finally:
1037
1054
        bzrlib.trace.close_trace()