Skip to content

Commit a164f46

Browse files
committed
Better error handling, itterate on json stream directly.
Signed-off-by: Aaron Cowdin <[email protected]>
1 parent 7dffc46 commit a164f46

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

docker/models/images.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,18 @@ def build(self, **kwargs):
166166
resp = self.client.api.build(**kwargs)
167167
if isinstance(resp, six.string_types):
168168
return self.get(resp)
169-
events = list(json_stream(resp))
170-
if not events:
171-
return BuildError('Unknown')
172-
for event in events:
173-
if 'stream' in event:
169+
for chunk in json_stream(resp):
170+
if 'error' in chunk:
171+
raise BuildError(chunk['error'])
172+
break
173+
if 'stream' in chunk:
174174
match = re.search(r'(Successfully built |sha256:)([0-9a-f]+)',
175-
event.get('stream', ''))
175+
chunk['stream'])
176176
if match:
177177
image_id = match.group(2)
178178
return self.get(image_id)
179179

180-
event = events[-1]
181-
raise BuildError(event.get('error') or event)
180+
return BuildError('Unknown')
182181

183182
def get(self, name):
184183
"""

0 commit comments

Comments
 (0)