From patchwork Mon Jun 12 16:17:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [7, of, 7] profile: properly propagate exception from the sub-context manager From: Pierre-Yves David X-Patchwork-Id: 21345 Message-Id: <2a4ee2a67d3f003ac2cb.1497284271@nodosa.octopoid.net> To: mercurial-devel@mercurial-scm.org Date: Mon, 12 Jun 2017 18:17:51 +0200 # HG changeset patch # User Pierre-Yves David # Date 1497281050 -7200 # Mon Jun 12 17:24:10 2017 +0200 # Node ID 2a4ee2a67d3f003ac2cbe1cf7f8cf5c7adf83efa # Parent b398563a8ca6167ceb94a2bdc19bdcdb92162636 # EXP-Topic profile # Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ # hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 2a4ee2a67d3f profile: properly propagate exception from the sub-context manager Context manager has a mechanism to control extension propagation. It is not used by profiling right now, but making the code correct will help prevent bug in the future. diff --git a/mercurial/profiling.py b/mercurial/profiling.py --- a/mercurial/profiling.py +++ b/mercurial/profiling.py @@ -214,8 +214,10 @@ class profile(object): raise def __exit__(self, exception_type, exception_value, traceback): + propagate = None if self._profiler is not None: - self._profiler.__exit__(exception_type, exception_value, traceback) + propagate = self._profiler.__exit__(exception_type, exception_value, + traceback) if self._output == 'blackbox': val = 'Profile:\n%s' % self._fp.getvalue() # ui.log treats the input as a format string, @@ -223,6 +225,7 @@ class profile(object): val = val.replace('%', '%%') self._ui.log('profile', val) self._closefp() + return propagate def _closefp(self): if self._fpdoclose and self._fp is not None: