1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6import 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
25