blob: b47975a4bc000bca7fee099a05bfcce2a4963b6c [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05004import subprocess
5
6class OETestCalledProcessError(subprocess.CalledProcessError):
7 def __str__(self):
8 def strify(o):
9 if isinstance(o, bytes):
10 return o.decode("utf-8", errors="replace")
11 else:
12 return o
13
14 s = "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
15 if hasattr(self, "output") and self.output:
16 s = s + "\nStandard Output: " + strify(self.output)
17 if hasattr(self, "stderr") and self.stderr:
18 s = s + "\nStandard Error: " + strify(self.stderr)
19 return s
20
21def errors_have_output():
22 subprocess.CalledProcessError = OETestCalledProcessError