xref: /OK3568_Linux_fs/yocto/poky/meta/lib/oeqa/utils/subprocesstweak.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#
2# SPDX-License-Identifier: MIT
3#
4import 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
23