Issue #27167: Clarify the subprocess.CalledProcessError error message text

when the child process died due to a signal.
This commit is contained in:
Gregory P. Smith ext:(%20%5BGoogle%20Inc.%5D) 2016-06-03 06:14:06 +00:00
parent 287e687648
commit d6da7604d3
3 changed files with 37 additions and 4 deletions

View file

@ -372,9 +372,11 @@ class SubprocessError(Exception): pass
class CalledProcessError(SubprocessError):
"""This exception is raised when a process run by check_call() or
check_output() returns a non-zero exit status.
The exit status will be stored in the returncode attribute;
"""Raised when a check_call() or check_output() process returns non-zero.
The exit status will be stored in the returncode attribute, negative
if it represents a signal number.
check_output() will also store the output in the output attribute.
"""
def __init__(self, returncode, cmd, output=None, stderr=None):
@ -384,7 +386,16 @@ class CalledProcessError(SubprocessError):
self.stderr = stderr
def __str__(self):
return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
if self.returncode and self.returncode < 0:
try:
return "Command '%s' died with %r." % (
self.cmd, signal.Signals(-self.returncode))
except ValueError:
return "Command '%s' died with unknown signal %d." % (
self.cmd, -self.returncode)
else:
return "Command '%s' returned non-zero exit status %d." % (
self.cmd, self.returncode)
@property
def stdout(self):