Rev 4944: Do not fiddle with exceptions in the pre_change_branch_tip hook running code. in http://bazaar.launchpad.net/~lifeless/bzr/hooks

Robert Collins robertc at robertcollins.net
Fri Jan 8 05:28:42 GMT 2010


At http://bazaar.launchpad.net/~lifeless/bzr/hooks

------------------------------------------------------------
revno: 4944
revision-id: robertc at robertcollins.net-20100108052817-qt0ubq2sat7f08pt
parent: pqm at pqm.ubuntu.com-20100108033509-5dp440ermqsavlhr
committer: Robert Collins <robertc at robertcollins.net>
branch nick: hooks
timestamp: Fri 2010-01-08 16:28:17 +1100
message:
  Do not fiddle with exceptions in the pre_change_branch_tip hook running code.
=== modified file 'NEWS'
--- a/NEWS	2010-01-08 03:35:09 +0000
+++ b/NEWS	2010-01-08 05:28:17 +0000
@@ -109,6 +109,9 @@
   CamelCase. For the features that were more likely to be used, we added a
   deprecation thunk, but not all. (John Arbash Meinel)
 
+* The Branch hooks pre_change_branch_tip no longer masks exceptions raised
+  by plugins - the original exceptions are now preserved. (Robert Collins)
+
 * The Transport ``Server.tearDown`` method is now renamed to
   ``stop_server`` and ``setUp`` to ``start_server`` for consistency with
   our normal naming pattern, and to avoid confusion with Python's

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2009-12-17 10:01:25 +0000
+++ b/bzrlib/branch.py	2010-01-08 05:28:17 +0000
@@ -1103,15 +1103,7 @@
         params = ChangeBranchTipParams(
             self, old_revno, new_revno, old_revid, new_revid)
         for hook in hooks:
-            try:
-                hook(params)
-            except errors.TipChangeRejected:
-                raise
-            except Exception:
-                exc_info = sys.exc_info()
-                hook_name = Branch.hooks.get_hook_name(hook)
-                raise errors.HookFailed(
-                    'pre_change_branch_tip', hook_name, exc_info)
+            hook(params)
 
     @needs_write_lock
     def update(self):

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2009-12-25 13:47:23 +0000
+++ b/bzrlib/errors.py	2010-01-08 05:28:17 +0000
@@ -2942,12 +2942,17 @@
 class HookFailed(BzrError):
     """Raised when a pre_change_branch_tip hook function fails anything other
     than TipChangeRejected.
+
+    Note that this exception is no longer raised, and the import is only left
+    to be nice to code which might catch it in a plugin.
     """
 
     _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
             "%(traceback_text)s%(exc_value)s")
 
     def __init__(self, hook_stage, hook_name, exc_info):
+        warn("BzrError HookFailed has been deprecated as of bzrlib 2.1.",
+                DeprecationWarning)
         import traceback
         self.hook_stage = hook_stage
         self.hook_name = hook_name

=== modified file 'bzrlib/tests/per_branch/test_hooks.py'
--- a/bzrlib/tests/per_branch/test_hooks.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/per_branch/test_hooks.py	2010-01-08 05:28:17 +0000
@@ -208,10 +208,7 @@
         branch.set_last_revision_info(0, NULL_REVISION)
 
     def test_hook_failure_prevents_change(self):
-        """If a hook raises an exception, the change does not take effect.
-
-        Also, a HookFailed exception will be raised.
-        """
+        """If a hook raises an exception, the change does not take effect."""
         branch = self.make_branch_with_revision_ids(
             'one-\xc2\xb5', 'two-\xc2\xb5')
         class PearShapedError(Exception):
@@ -221,8 +218,7 @@
         Branch.hooks.install_named_hook(
             'pre_change_branch_tip', hook_that_raises, None)
         hook_failed_exc = self.assertRaises(
-            HookFailed, branch.set_last_revision_info, 0, NULL_REVISION)
-        self.assertIsInstance(hook_failed_exc.exc_value, PearShapedError)
+            PearShapedError, branch.set_last_revision_info, 0, NULL_REVISION)
         # The revision info is unchanged.
         self.assertEqual((2, 'two-\xc2\xb5'), branch.last_revision_info())
 




More information about the bazaar-commits mailing list