aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2021-04-21 20:22:13 -0400
committerMike Frysinger <vapier@google.com>2021-04-21 20:23:49 -0400
commit216334058f60313bb4603e54d9dfad688aad74e6 (patch)
tree0ea961ec9106553c9322f503379765a87760ab4a
parent95795d8710949b4108b9f0262c14d8d8daa216d0 (diff)
downloadrepohooks-216334058f60313bb4603e54d9dfad688aad74e6.tar.gz
utils: run: fix crash with failing tools & combined stderrandroid-s-beta-4android-s-beta-3android-s-beta-2android-s-beta-1android-s-beta-4
If we try to run a program that doesn't exist, don't crash while trying to show the errors to the user. Bug: 185946409 Test: pre-upload unittests pass Change-Id: I70e00412bd000e907536011d245eaa82d36634f6
-rw-r--r--rh/utils.py4
-rwxr-xr-xrh/utils_unittest.py9
2 files changed, 11 insertions, 2 deletions
diff --git a/rh/utils.py b/rh/utils.py
index f59998c..aeab52f 100644
--- a/rh/utils.py
+++ b/rh/utils.py
@@ -417,9 +417,9 @@ def run(cmd, redirect_stdout=False, redirect_stderr=False, cwd=None, input=None,
stderr=ensure_text(result.stderr))
except OSError as e:
# Avoid leaking tempfiles.
- if popen_stdout is not None:
+ if popen_stdout is not None and not isinstance(popen_stdout, int):
popen_stdout.close()
- if popen_stderr is not None:
+ if popen_stderr is not None and not isinstance(popen_stderr, int):
popen_stderr.close()
estr = str(e)
diff --git a/rh/utils_unittest.py b/rh/utils_unittest.py
index e6ecc97..ea2ddaa 100755
--- a/rh/utils_unittest.py
+++ b/rh/utils_unittest.py
@@ -206,6 +206,15 @@ class RunCommandTests(unittest.TestCase):
self.assertNotEqual(0, ret.returncode)
self.assertIn('a/b/c/d', str(ret))
+ def test_check_false_missing_prog_combined_output(self):
+ """Verify handling of combined output capturing w/missing progs."""
+ with self.assertRaises(rh.utils.CalledProcessError) as e:
+ rh.utils.run(['./!~a/b/c/d/'], check=True,
+ combine_stdout_stderr=True)
+ err = e.exception
+ self.assertNotEqual(0, err.returncode)
+ self.assertIn('a/b/c/d', str(err))
+
if __name__ == '__main__':
unittest.main()