Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions python/rpdk/python/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import docker
from docker.errors import APIError, ContainerError, ImageLoadError
from requests.exceptions import ConnectionError as RequestsConnectionError
from rpdk.core.data_loaders import resource_stream
from rpdk.core.exceptions import DownstreamError, SysExitRecommendedError
from rpdk.core.init import input_with_validation
Expand Down Expand Up @@ -249,6 +250,15 @@ def _docker_build(cls, external_path):
volumes=volumes,
stream=True,
)
except RequestsConnectionError as e:
# it seems quite hard to reliably extract the cause from
# ConnectionError. we replace it with a friendlier error message
# and preserve the cause for debug traceback
cause = RequestsConnectionError(
"Could not connect to docker - is it running?"
)
cause.__cause__ = e
raise DownstreamError("Error running docker build") from cause
except (ContainerError, ImageLoadError, APIError) as e:
raise DownstreamError("Error running docker build") from e
LOG.debug("Build running. Output:")
Expand Down
4 changes: 4 additions & 0 deletions tests/plugin/codegen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest

from docker.errors import APIError, ContainerError, ImageLoadError
from requests.exceptions import ConnectionError as RequestsConnectionError
from rpdk.core.exceptions import DownstreamError
from rpdk.core.project import Project
from rpdk.python.codegen import (
Expand Down Expand Up @@ -252,6 +253,9 @@ def test__docker_build_good_path(plugin, tmp_path):
lambda: ContainerError("abcde", 255, "/bin/false", "image", ""),
ImageLoadError,
lambda: APIError("500"),
lambda: RequestsConnectionError(
"Connection aborted.", ConnectionRefusedError(61, "Connection refused")
),
],
)
def test__docker_build_bad_path(plugin, tmp_path, exception):
Expand Down