Fix stderr on returncode is different of 0

Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Ulysses Souza 2020-08-31 21:16:18 +02:00
parent e9b93d706f
commit 3b17b3c2c0
3 changed files with 9 additions and 10 deletions

View File

@ -73,13 +73,16 @@ def main():
log.error(e.msg)
sys.exit(1)
except BuildError as e:
log.error("Service '{}' failed to build: {}".format(e.service.name, e.reason))
reason = ""
if e.reason:
reason = " : " + e.reason
log.error("Service '{}' failed to build{}".format(e.service.name, reason))
sys.exit(1)
except StreamOutputError as e:
log.error(e)
sys.exit(1)
except NeedsBuildError as e:
log.error("Service '%s' needs to be built, but --no-build was passed." % e.service.name)
log.error("Service '{}' needs to be built, but --no-build was passed.".format(e.service.name))
sys.exit(1)
except NoSuchCommand as e:
commands = "\n".join(parse_doc_section("commands:", getdoc(e.supercommand)))

View File

@ -1857,7 +1857,6 @@ class _CLIBuilder:
magic_word = "Successfully built "
appear = False
with subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True) as p:
while True:
line = p.stdout.readline()
@ -1867,9 +1866,9 @@ class _CLIBuilder:
appear = True
yield json.dumps({"stream": line})
err = p.stderr.readline().strip()
if err:
raise StreamOutputError(err)
p.communicate()
if p.returncode != 0:
raise StreamOutputError()
with open(iidfile) as f:
line = f.readline()

View File

@ -1002,12 +1002,9 @@ class ServiceTest(DockerClientTestCase):
'context': base_dir,
'labels': {'com.docker.compose.test': 'true'}},
)
with pytest.raises(BuildError) as excinfo:
with pytest.raises(BuildError):
service.build(cli=True)
reason = excinfo.value.reason
assert "The command '/bin/sh -c exit 2' returned a non-zero code: 2" == reason
def test_up_build_cli(self):
base_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, base_dir)