Rev 2837: Return exitcode 4 on internal error in http://sourcefrog.net/bzr/test-traceback

Martin Pool mbp at sourcefrog.net
Mon Sep 24 07:42:30 BST 2007


At http://sourcefrog.net/bzr/test-traceback

------------------------------------------------------------
revno: 2837
revision-id: mbp at sourcefrog.net-20070924064221-nu12try0hbilenlj
parent: mbp at sourcefrog.net-20070921060245-j6a3g6oxdbs1bdjn
parent: mbp at sourcefrog.net-20070820060505-4ywu68q7scnbfmat
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: test-traceback
timestamp: Mon 2007-09-24 16:42:21 +1000
message:
  Return exitcode 4 on internal error
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
  bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
  bzrlib/tests/blackbox/test_exceptions.py test_exceptions.py-20060604211237-yi2cxg0ose3xk4id-1
  bzrlib/trace.py                trace.py-20050309040759-c8ed824bdcd4748a
  doc/developers/HACKING.txt     HACKING-20050805200004-2a5dc975d870f78c
    ------------------------------------------------------------
    revno: 2713.2.3
    revision-id: mbp at sourcefrog.net-20070820060505-4ywu68q7scnbfmat
    parent: mbp at sourcefrog.net-20070820041609-gere4zndmrvviwji
    parent: pqm at pqm.ubuntu.com-20070820045741-zojy0q9vgi0d860r
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: error-exitcode
    timestamp: Mon 2007-08-20 16:05:05 +1000
    message:
      merge trunk
    added:
      bzrlib/tests/blackbox/test_bundle_info.py test_bundle_info.py-20070816181255-eiuodwxuqu7w7gxf-1
      bzrlib/tests/repository_implementations/test_fetch.py test_fetch.py-20070814052151-5cxha9slx4c93uog-1
    modified:
      Makefile                       Makefile-20050805140406-d96e3498bb61c5bb
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/bundle/commands.py      __init__.py-20050617152058-1b6530d9ab85c11c
      bzrlib/bundle/serializer/v4.py v10.py-20070611062757-5ggj7k18s9dej0fr-1
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
      bzrlib/patches.py              patches.py-20050727183609-378c1cc5972ce908
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/store/revision/knit.py  knit.py-20060303020652-de5fa299e941a3c7
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/blackbox/__init__.py __init__.py-20051128053524-eba30d8255e08dc3
      bzrlib/tests/blackbox/test_checkout.py test_checkout.py-20060211231752-a5cde67cf70af854
      bzrlib/tests/blackbox/test_info.py test_info.py-20060215045507-bbdd2d34efab9e0a
      bzrlib/tests/branch_implementations/test_branch.py testbranch.py-20050711070244-121d632bc37d7253
      bzrlib/tests/branch_implementations/test_hooks.py test_hooks.py-20070129154855-blhpwxmvjs07waei-1
      bzrlib/tests/branch_implementations/test_revision_history.py test_revision_histor-20070326062311-v7co92liyuchb80w-1
      bzrlib/tests/repository_implementations/__init__.py __init__.py-20060131092037-9564957a7d4a841b
      bzrlib/tests/repository_implementations/test_repository.py test_repository.py-20060131092128-ad07f494f5c9d26c
      bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
      bzrlib/tests/test_bundle.py    test.py-20050630184834-092aa401ab9f039c
      bzrlib/tests/test_fetch.py     testfetch.py-20050825090644-f73e07e7dfb1765a
      bzrlib/tests/test_lockdir.py   test_lockdir.py-20060220222025-33d4221569a3d600
      bzrlib/tests/test_patches.py   test_patches.py-20051231203844-f4974d20f6aea09c
      bzrlib/tests/test_revision.py  testrevision.py-20050804210559-46f5e1eb67b01289
      bzrlib/transport/http/wsgi.py  wsgi.py-20061005091552-rz8pva0olkxv0sd8-2
      bzrlib/transport/sftp.py       sftp.py-20051019050329-ab48ce71b7e32dfe
      bzrlib/transport/ssh.py        ssh.py-20060824042150-0s9787kng6zv1nwq-1
    ------------------------------------------------------------
    revno: 2713.2.2
    revision-id: mbp at sourcefrog.net-20070820041609-gere4zndmrvviwji
    parent: mbp at sourcefrog.net-20070816075121-fr9221nx4clj2eoz
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: error-exitcode
    timestamp: Mon 2007-08-20 14:16:09 +1000
    message:
      Add mention of exitcode 4 for internal errors
    modified:
      bzrlib/tests/blackbox/test_exceptions.py test_exceptions.py-20060604211237-yi2cxg0ose3xk4id-1
      doc/developers/HACKING.txt     HACKING-20050805200004-2a5dc975d870f78c
    ------------------------------------------------------------
    revno: 2713.2.1
    revision-id: mbp at sourcefrog.net-20070816075121-fr9221nx4clj2eoz
    parent: pqm at pqm.ubuntu.com-20070816055011-tnjdmdi948uyvz6a
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: error-exitcode
    timestamp: Thu 2007-08-16 17:51:21 +1000
    message:
      Return exitcode 4 if an internal error occurs
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/tests/blackbox/test_exceptions.py test_exceptions.py-20060604211237-yi2cxg0ose3xk4id-1
      bzrlib/trace.py                trace.py-20050309040759-c8ed824bdcd4748a
=== modified file 'NEWS'
--- a/NEWS	2007-09-21 06:02:45 +0000
+++ b/NEWS	2007-09-24 06:42:21 +0000
@@ -9,6 +9,11 @@
 
   NOTES WHEN UPGRADING:
 
+  CHANGES:
+  
+    * ``bzr`` now returns exit code 4 if an internal error occurred, and 
+      3 if a normal error occurred.  (Martin Pool)
+
   FEATURES:
 
    * New ``reconfigure`` command (Aaron Bentley)

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2007-09-18 05:35:31 +0000
+++ b/bzrlib/commands.py	2007-09-24 06:42:21 +0000
@@ -803,12 +803,12 @@
     except (KeyboardInterrupt, Exception), e:
         # used to handle AssertionError and KeyboardInterrupt
         # specially here, but hopefully they're handled ok by the logger now
-        trace.report_exception(sys.exc_info(), sys.stderr)
+        exitcode = trace.report_exception(sys.exc_info(), sys.stderr)
         if os.environ.get('BZR_PDB'):
             print '**** entering debugger'
             import pdb
             pdb.post_mortem(sys.exc_traceback)
-        return 3
+        return exitcode
 
 
 def run_bzr_catch_user_errors(argv):

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2007-09-13 01:54:49 +0000
+++ b/bzrlib/errors.py	2007-09-24 06:42:21 +0000
@@ -44,6 +44,11 @@
 # 'unprintable'.
 
 
+# return codes from the bzr program
+EXIT_ERROR = 3
+EXIT_INTERNAL_ERROR = 4
+
+
 class BzrError(StandardError):
     """
     Base class for errors raised by bzrlib.

=== modified file 'bzrlib/tests/blackbox/test_exceptions.py'
--- a/bzrlib/tests/blackbox/test_exceptions.py	2007-09-18 05:40:09 +0000
+++ b/bzrlib/tests/blackbox/test_exceptions.py	2007-09-24 06:42:21 +0000
@@ -22,6 +22,7 @@
 
 from bzrlib import (
     bzrdir,
+    errors,
     repository,
     trace,
     )
@@ -44,6 +45,16 @@
             r'bzr: ERROR: exceptions\.AssertionError: failed\n')
         self.assertContainsRe(err,
             r'please send this report to')
+
+    def test_exception_exitcode(self):
+        # we must use a subprocess, because the normal in-memory mechanism
+        # allows errors to propagate up through the test suite
+        self.run_bzr_subprocess(['assert-fail'],
+            retcode=errors.EXIT_INTERNAL_ERROR)
+
+
+    # TODO: assert-fail doesn't need to always be present; we could just
+    # register (and unregister) it from tests that want to touch it.
     
 
 class TestDeprecationWarning(TestCaseInTempDir):

=== modified file 'bzrlib/trace.py'
--- a/bzrlib/trace.py	2007-09-18 05:35:31 +0000
+++ b/bzrlib/trace.py	2007-09-24 06:42:21 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -65,7 +65,10 @@
 import bzrlib
 
 lazy_import(globals(), """
-from bzrlib import debug
+from bzrlib import (
+    debug,
+    errors,
+    )
 """)
 
 _file_handler = None
@@ -309,6 +312,10 @@
 
 def report_exception(exc_info, err_file):
     """Report an exception to err_file (typically stderr) and to .bzr.log.
+
+    This will show either a full traceback or a short message as appropriate.
+
+    :return: The appropriate exit code for this error.
     """
     exc_type, exc_object, exc_tb = exc_info
     # Log the full traceback to ~/.bzr.log
@@ -316,16 +323,21 @@
     if (isinstance(exc_object, IOError)
         and getattr(exc_object, 'errno', None) == errno.EPIPE):
         print >>err_file, "bzr: broken pipe"
+        return errors.EXIT_ERROR
     elif isinstance(exc_object, KeyboardInterrupt):
         print >>err_file, "bzr: interrupted"
+        return errors.EXIT_ERROR
     elif not getattr(exc_object, 'internal_error', True):
         report_user_error(exc_info, err_file)
+        return errors.EXIT_ERROR
     elif isinstance(exc_object, (OSError, IOError)):
         # Might be nice to catch all of these and show them as something more
         # specific, but there are too many cases at the moment.
         report_user_error(exc_info, err_file)
+        return errors.EXIT_ERROR
     else:
         report_bug(exc_info, err_file)
+        return errors.EXIT_INTERNAL_ERROR
 
 
 # TODO: Should these be specially encoding the output?

=== modified file 'doc/developers/HACKING.txt'
--- a/doc/developers/HACKING.txt	2007-09-10 10:05:51 +0000
+++ b/doc/developers/HACKING.txt	2007-09-24 06:42:21 +0000
@@ -1081,6 +1081,7 @@
     2. Unrepresentable diff changes (i.e. binary files that we cannot show 
        a diff of).
     3. An error or exception has occurred.
+    4. An internal error occurred (one that shows a traceback.)
 
 Errors are handled through Python exceptions. Exceptions should be defined
 inside bzrlib.errors, so that we can see the whole tree at a glance.




More information about the bazaar-commits mailing list