This commit is contained in:
Khushiyant 2025-06-11 13:30:09 +02:00 committed by GitHub
commit 8a118243b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import logging
import os
from json import JSONDecodeError
from .. import auth, errors, utils
from ..constants import DEFAULT_DATA_CHUNK_SIZE
@ -495,7 +496,14 @@ class ImageApiMixin:
self._raise_for_status(response)
if stream:
return self._stream_helper(response, decode=decode)
try:
for line in self._stream_helper(response, decode=decode):
if isinstance(line, dict) and "errorDetail" in line:
message = line["errorDetail"]["message"]
raise errors.APIError(message=message)
yield line
except JSONDecodeError as e:
raise JSONDecodeError("Error decoding response stream") from e
return self._result(response)

View File

@ -4,6 +4,7 @@ import pytest
import docker
from docker import auth
import docker.errors
from . import fake_api
from .api_test import (
@ -288,6 +289,12 @@ class ImageTest(BaseAPIClientTest):
timeout=DEFAULT_TIMEOUT_SECONDS
)
def test_push_image_with_exception(self):
with pytest.raises(Exception):
self.client.push("docker", stream=True, tag='tag', decode=True)
self.fail('An exception should have been raised')
def test_tag_image(self):
self.client.tag(fake_api.FAKE_IMAGE_ID, fake_api.FAKE_REPO_NAME)