Skip to content

Commit b3f82db

Browse files
committed
exit and show clean error message (no log) if docker connection fails
1 parent c8cd326 commit b3f82db

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

repo2docker/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,10 @@ def build(self):
612612
docker_client = docker.APIClient(version="auto", **kwargs_from_env())
613613
except DockerException as e:
614614
self.log.error(
615-
"\nDocker client initialization error. Check if docker is running on the host.\n\n"
615+
"\nDocker client initialization error: %s.\nCheck if docker is running on the host.\n",
616+
e,
616617
)
617-
raise
618+
self.exit(1)
618619

619620
# If the source to be executed is a directory, continue using the
620621
# directory. In the case of a local directory, it is used as both the

tests/unit/test_app.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,23 @@ def test_root_not_allowed():
127127
builds.assert_called_once()
128128

129129

130-
def test_dryrun_works_without_docker(tmpdir):
130+
def test_dryrun_works_without_docker(tmpdir, capsys):
131131
with chdir(tmpdir):
132132
with patch.object(docker, "APIClient") as client:
133133
client.side_effect = docker.errors.DockerException("Error: no Docker")
134134
app = Repo2Docker(dry_run=True)
135135
app.build()
136+
captured = capsys.readouterr()
137+
assert "Error: no Docker" not in captured.err
136138

137139

138-
def test_error_log_without_docker(tmpdir, caplog):
140+
def test_error_log_without_docker(tmpdir, capsys):
139141
with chdir(tmpdir):
140142
with patch.object(docker, "APIClient") as client:
141143
client.side_effect = docker.errors.DockerException("Error: no Docker")
142144
app = Repo2Docker()
143145

144-
with pytest.raises(docker.errors.DockerException):
146+
with pytest.raises(SystemExit):
145147
app.build()
146-
147148
captured = capsys.readouterr()
148-
assert "Check if docker is running" in captured.err
149+
assert "Error: no Docker" in captured.err

tests/unit/test_argumentvalidation.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ def test_invalid_container_port_protocol_mapping_fail(temp_cwd):
223223
assert not validate_arguments(builddir, args_list, "Port specification")
224224

225225

226-
@pytest.mark.xfail(reason="Regression in new arg parsing")
227226
def test_docker_handle_fail(temp_cwd):
228227
"""
229228
Test to check if r2d fails with minimal error message on not being able to connect to docker daemon
@@ -233,19 +232,22 @@ def test_docker_handle_fail(temp_cwd):
233232
assert not validate_arguments(
234233
builddir,
235234
args_list,
236-
"Docker client initialization error. Check if docker is running on the host.",
235+
"Check if docker is running on the host.",
237236
disable_dockerd=True,
238237
)
239238

240239

241240
def test_docker_handle_debug_fail(temp_cwd):
242241
"""
243-
Test to check if r2d fails with stack trace on not being able to connect to docker daemon and debug enabled
242+
Test to check if r2d fails with helpful error message on not being able to connect to docker daemon and debug enabled
244243
"""
245244
args_list = ["--debug"]
246245

247246
assert not validate_arguments(
248-
builddir, args_list, "docker.errors.DockerException", disable_dockerd=True
247+
builddir,
248+
args_list,
249+
"Check if docker is running on the host.",
250+
disable_dockerd=True,
249251
)
250252

251253

0 commit comments

Comments
 (0)