From dc8185f2a9af53fd91fef160313564ad1abf827f Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 27 Mar 2025 17:06:11 -0400 Subject: [PATCH] launcher: change RunError to subprocess.CalledProcessError Since we require Python 3.6 now in the launcher, swap out our custom RunError class for the standard subprocess one. Change-Id: Id0ca17c40e22ece03e06366a263ad340963f979d Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/464401 Commit-Queue: Mike Frysinger Reviewed-by: Scott Lee Tested-by: Mike Frysinger --- repo | 13 +++++-------- tests/test_wrapper.py | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/repo b/repo index 21085688..782afb6e 100755 --- a/repo +++ b/repo @@ -482,11 +482,6 @@ def InitParser(parser): return parser -# This is a poor replacement for subprocess.run until we require Python 3.6+. -class RunError(Exception): - """Error when running a command failed.""" - - def run_command(cmd, **kwargs): """Run |cmd| and return its output.""" check = kwargs.pop("check", False) @@ -544,7 +539,8 @@ def run_command(cmd, **kwargs): _print_output("stdout", ret.stdout) _print_output("stderr", ret.stderr) - raise RunError(ret) + # This will raise subprocess.CalledProcessError for us. + ret.check_returncode() return ret @@ -668,7 +664,7 @@ def run_git(*args, **kwargs): file=sys.stderr, ) sys.exit(1) - except RunError: + except subprocess.CalledProcessError: raise CloneFailure() @@ -850,7 +846,8 @@ def _GetRepoConfig(name): f"repo: error: git {' '.join(cmd)} failed:\n{ret.stderr}", file=sys.stderr, ) - raise RunError() + # This will raise subprocess.CalledProcessError for us. + ret.check_returncode() def _InitHttp(): diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py index 8bb5eb28..77ceda8f 100644 --- a/tests/test_wrapper.py +++ b/tests/test_wrapper.py @@ -126,7 +126,7 @@ class RunCommand(RepoWrapperTestCase): self.wrapper.run_command(["true"], check=False) self.wrapper.run_command(["true"], check=True) self.wrapper.run_command(["false"], check=False) - with self.assertRaises(self.wrapper.RunError): + with self.assertRaises(subprocess.CalledProcessError): self.wrapper.run_command(["false"], check=True)