Patchwork [7,of,7] profile: properly propagate exception from the sub-context manager

login
register
mail settings
Submitter Pierre-Yves David
Date June 12, 2017, 4:17 p.m.
Message ID <2a4ee2a67d3f003ac2cb.1497284271@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21345/
State Accepted
Headers show

Comments

Pierre-Yves David - June 12, 2017, 4:17 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# 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.
Sean Farley - June 13, 2017, 5:40 a.m.
Pierre-Yves David <pierre-yves.david@ens-lyon.org> writes:

> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@octobus.net>
> # 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.

I've queued this series with the function call fixed in patch 5; thanks!

Patch

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: