exit and show clean error message (no log) if docker connection fails
MODIFY
repo2docker/app.py
repo2docker/app.py
@@ -612,9 +612,10 @@ class Repo2Docker(Application):
docker_client = docker.APIClient(version="auto", **kwargs_from_env())
except DockerException as e:
self.log.error(
- "\nDocker client initialization error. Check if docker is running on the host.\n\n"
+ "\nDocker client initialization error: %s.\nCheck if docker is running on the host.\n",
+ e,
)
- raise
+ self.exit(1)
# If the source to be executed is a directory, continue using the
# directory. In the case of a local directory, it is used as both the

MODIFY
tests/unit/test_app.py
tests/unit/test_app.py
@@ -127,22 +127,23 @@ def test_root_not_allowed():
builds.assert_called_once()
-def test_dryrun_works_without_docker(tmpdir):
+def test_dryrun_works_without_docker(tmpdir, capsys):
with chdir(tmpdir):
with patch.object(docker, "APIClient") as client:
client.side_effect = docker.errors.DockerException("Error: no Docker")
app = Repo2Docker(dry_run=True)
app.build()
+ captured = capsys.readouterr()
+ assert "Error: no Docker" not in captured.err
-def test_error_log_without_docker(tmpdir, caplog):
+def test_error_log_without_docker(tmpdir, capsys):
with chdir(tmpdir):
with patch.object(docker, "APIClient") as client:
client.side_effect = docker.errors.DockerException("Error: no Docker")
app = Repo2Docker()
- with pytest.raises(docker.errors.DockerException):
+ with pytest.raises(SystemExit):
app.build()
-
captured = capsys.readouterr()
- assert "Check if docker is running" in captured.err
+ assert "Error: no Docker" in captured.err

MODIFY
tests/unit/test_argumentvalidation.py
tests/unit/test_argumentvalidation.py
@@ -223,7 +223,6 @@ def test_invalid_container_port_protocol_mapping_fail(temp_cwd):
assert not validate_arguments(builddir, args_list, "Port specification")
-@pytest.mark.xfail(reason="Regression in new arg parsing")
def test_docker_handle_fail(temp_cwd):
"""
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):
assert not validate_arguments(
builddir,
args_list,
- "Docker client initialization error. Check if docker is running on the host.",
+ "Check if docker is running on the host.",
disable_dockerd=True,
)
def test_docker_handle_debug_fail(temp_cwd):
"""
- Test to check if r2d fails with stack trace on not being able to connect to docker daemon and debug enabled
+ Test to check if r2d fails with helpful error message on not being able to connect to docker daemon and debug enabled
"""
args_list = ["--debug"]
assert not validate_arguments(
- builddir, args_list, "docker.errors.DockerException", disable_dockerd=True
+ builddir,
+ args_list,
+ "Check if docker is running on the host.",
+ disable_dockerd=True,
)

exit and show clean error message (no log) if docker connection fails