diff options
author | Guido Günther <agx@sigxcpu.org> | 2016-11-04 16:19:35 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2016-11-04 16:26:10 +0100 |
commit | ea5775a23e5223026b37100d23229b1bfc39bafa (patch) | |
tree | 3f715a64685ce1a5880a13d0706d8fea4cae8329 | |
parent | ced46db062f8e38c0eed7d1feb6e6e8b0d6435f9 (diff) |
commands: allow to fall back to error reason if stderr is empty
Use this in PristineTar and SrcRpmFile to give better error messages if
the command doesn't even get to print to stderr (i.e. missing on disk).
Closes: #842592
-rw-r--r-- | gbp/command_wrappers.py | 2 | ||||
-rw-r--r-- | gbp/pkg/pristinetar.py | 4 | ||||
-rw-r--r-- | gbp/rpm/__init__.py | 2 | ||||
-rw-r--r-- | tests/21_test_command_wrappers.py | 15 |
4 files changed, 20 insertions, 3 deletions
diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py index e16c1080..f4b00b89 100644 --- a/gbp/command_wrappers.py +++ b/gbp/command_wrappers.py @@ -140,8 +140,10 @@ class Command(object): """ stdout = self.stdout.rstrip() if self.stdout else self.stdout stderr = self.stderr.rstrip() if self.stderr else self.stderr + stderr_or_reason = self.stderr.rstrip() if self.stderr else self.err_reason return self.run_error.format(stdout=stdout, stderr=stderr, + stderr_or_reason=stderr_or_reason, err_reason=self.err_reason) def __call__(self, args=[], quiet=False): diff --git a/gbp/pkg/pristinetar.py b/gbp/pkg/pristinetar.py index ac24998f..79e1334e 100644 --- a/gbp/pkg/pristinetar.py +++ b/gbp/pkg/pristinetar.py @@ -64,7 +64,7 @@ class PristineTar(Command): @param archive: the name of the orig archive @type archive: C{str} """ - self.run_error = 'Pristine-tar couldn\'t checkout "%s": {stderr}' % os.path.basename(archive) + self.run_error = 'Pristine-tar couldn\'t checkout "%s": {stderr_or_reason}' % os.path.basename(archive) self.__call__(['checkout', archive]) def commit(self, archive, upstream): @@ -77,6 +77,6 @@ class PristineTar(Command): @param upstream: the upstream branch to diff against @type upstream: C{str} """ - self.run_error = ("Couldn't commit to '%s' with upstream '%s': {stderr}" % + self.run_error = ("Couldn't commit to '%s' with upstream '%s': {stderr_or_reason}" % (self.branch, upstream)) self.__call__(['commit', archive, upstream]) diff --git a/gbp/rpm/__init__.py b/gbp/rpm/__init__.py index 119d55ed..5a9a6688 100644 --- a/gbp/rpm/__init__.py +++ b/gbp/rpm/__init__.py @@ -99,7 +99,7 @@ class SrcRpmFile(object): c = gbpc.RunAtCommand('rpm2cpio', [self.srpmfile, '|', 'cpio', '-id'], shell=True, capture_stderr=True) - c.run_error = "'%s' failed: {stderr}" % (" ".join([c.cmd] + c.args)) + c.run_error = "'%s' failed: {stderr_or_reason}" % (" ".join([c.cmd] + c.args)) c(dir=dest_dir) diff --git a/tests/21_test_command_wrappers.py b/tests/21_test_command_wrappers.py index 4dfbb48e..fd442c82 100644 --- a/tests/21_test_command_wrappers.py +++ b/tests/21_test_command_wrappers.py @@ -63,6 +63,21 @@ class TestCommandWrapperFailures(unittest.TestCase, GbpLogTester): self.assertEqual(self.false.stderr, '') self.assertEqual(self.false.stdout, 'we have a problem') + def test_log_use_err_or_reason_for_error_messge_reason(self): + self.false.run_error = "AFAIK {stderr_or_reason}" + with self.assertRaises(CommandExecFailed): + self.false.__call__() + self.log_tester._check_log(0, "gbp:error: AFAIK execution failed: .Errno 2. No such file or directory") + self.assertEqual(self.false.retcode, 1) + + @patch_popen(stderr='we have a problem', returncode=1) + def test_log_use_err_or_reason_for_error_messge_error(self, create_mock): + self.false.run_error = "Erpel {stderr_or_reason}" + with self.assertRaises(CommandExecFailed): + self.false.__call__() + self.log_tester._check_log(0, "gbp:error: Erpel we have a problem") + self.assertEqual(self.false.retcode, 1) + @patch_popen(returncode=0) def test_no_log_on_success(self, create_mock): self.false.__call__() |