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