Skip to content

Commit 8b5a52a

Browse files
committed
Error handling in ImageCollection.load
Signed-off-by: Joffrey F <[email protected]>
1 parent 601c5a4 commit 8b5a52a

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

docker/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ class BuildError(Exception):
144144
pass
145145

146146

147+
class ImageLoadError(DockerException):
148+
pass
149+
150+
147151
def create_unexpected_kwargs_error(name, kwargs):
148152
quoted_kwargs = ["'{}'".format(k) for k in sorted(kwargs)]
149153
text = ["{}() ".format(name)]

docker/models/images.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import six
44

55
from ..api import APIClient
6-
from ..errors import BuildError
6+
from ..errors import BuildError, ImageLoadError
77
from ..utils.json_stream import json_stream
88
from .resource import Collection, Model
99

@@ -258,6 +258,9 @@ def load(self, data):
258258
if match:
259259
image_id = match.group(2)
260260
images.append(image_id)
261+
if 'error' in chunk:
262+
raise ImageLoadError(chunk['error'])
263+
261264
return [self.get(i) for i in images]
262265

263266
def pull(self, name, tag=None, **kwargs):

tests/integration/models_images_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ def test_pull_with_tag(self):
7171
image = client.images.pull('alpine', tag='3.3')
7272
assert 'alpine:3.3' in image.attrs['RepoTags']
7373

74+
def test_load_error(self):
75+
client = docker.from_env(version=TEST_API_VERSION)
76+
with pytest.raises(docker.errors.ImageLoadError):
77+
client.images.load('abc')
78+
7479

7580
class ImageTest(BaseIntegrationTest):
7681

0 commit comments

Comments
 (0)