This is an automated email from the ASF dual-hosted git repository.

rzo1 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/storm.git


The following commit(s) were added to refs/heads/master by this push:
     new 22a8483e9f docker-to-squash.py: don't return from finally in 
shell_command (#9293)
22a8483e9f is described below

commit 22a8483e9f4c5f71fdc4efbb7af150fc357870a0
Author: linzch3 <[email protected]>
AuthorDate: Mon Nov 23 13:55:28 2026 -0500

    docker-to-squash.py: don't return from finally in shell_command (#9293)
    
    The return in the finally clause discarded the exception, so
    raise_on_error=True never raised. Return after the try instead, and only
    re-raise launch errors when raise_on_error is set so callers passing False
    still get the -1 return code.
    
    Fixes #9289
---
 bin/docker-to-squash.py      |  9 ++++++---
 bin/test_docker_to_squash.py | 13 +++++++++----
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/bin/docker-to-squash.py b/bin/docker-to-squash.py
index 4ea3a371f6..ea07530229 100755
--- a/bin/docker-to-squash.py
+++ b/bin/docker-to-squash.py
@@ -88,12 +88,15 @@ def shell_command(command, print_stdout, print_stderr, 
raise_on_error, timeout_s
     except Exception as ex:
         if process and process.poll() is None:
             process.kill()
-        raise Exception("Popen failure, " + str(ex))
+        if raise_on_error:
+            raise Exception("Popen failure, " + str(ex)) from ex
+        logging.debug("command %s failed: %s", command, ex)
     finally:
-        # Note that finally clause executes even when there is no exception, 
hence the "return" statement
         if timer:
             timer.cancel()
-        return out, err, (process.returncode if process else -1)
+
+    # Don't return from the finally clause, it would discard the exception 
raised above.
+    return out, err, (process.returncode if process else -1)
 
 
 def process_timeout(process):
diff --git a/bin/test_docker_to_squash.py b/bin/test_docker_to_squash.py
index d7a44e95b3..65f2b6d442 100644
--- a/bin/test_docker_to_squash.py
+++ b/bin/test_docker_to_squash.py
@@ -33,10 +33,15 @@ class Test(TestCase):
         out, err, rc = dtsq.shell_command(cmd, True, True, True, 
timeout_sec=10)
         self.assertEqual(0, rc, f"Failed 
cmd={cmd}\nrc={rc}\nout={out}\nerr={err}")
 
-        # expect failure
-        cmd = ["badcmd", "-l"]
-        out, err, rc = dtsq.shell_command(cmd, True, True, True, 
timeout_sec=10)
-        self.assertNotEqual(0, rc, f"Expected to fail 
cmd={cmd}\nrc={rc}\nout={out}\nerr={err}")
+        # expect failure, without raise_on_error the return code is returned
+        for cmd in (["badcmd", "-l"], ["false"]):
+            out, err, rc = dtsq.shell_command(cmd, True, True, False, 
timeout_sec=10)
+            self.assertNotEqual(0, rc, f"Expected to fail 
cmd={cmd}\nrc={rc}\nout={out}\nerr={err}")
+
+        # expect failure, with raise_on_error an exception is raised
+        for cmd in (["badcmd", "-l"], ["false"]):
+            with self.assertRaises(Exception, msg=f"Expected to raise 
cmd={cmd}"):
+                dtsq.shell_command(cmd, True, True, True, timeout_sec=10)
 
     # TODO:
     #  def test_read_image_tag_to_hash(self):

Reply via email to