aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2021-04-22 18:58:05 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-04-22 18:58:05 +0000
commit6a0019626a4e51628bc06f6390a81f510c88f8b2 (patch)
tree0ea961ec9106553c9322f503379765a87760ab4a
parent5926a5fa1b081fefa51d7356fe156b50758c9dd7 (diff)
parent216334058f60313bb4603e54d9dfad688aad74e6 (diff)
downloadrepohooks-6a0019626a4e51628bc06f6390a81f510c88f8b2.tar.gz
utils: run: fix crash with failing tools & combined stderr am: 216334058f
Original change: https://android-review.googlesource.com/c/platform/tools/repohooks/+/1684226 Change-Id: I6cd59a72e03e5645efa256377d53132e4e0c365b
-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()