From d5d25eba06e3afae1cfbcd10fd4395e0cd053bfb Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Fri, 6 Nov 2026 15:23:34 +0800 Subject: [PATCH] fix: stop reporting a missing image as a network problem A 404 from the registry means the image name is wrong or the registry needs authentication, but the pull wrapped every error with "please check your Internet connection". Say what actually failed and keep the network advice for the other errors. --- gns3server/compute/docker/__init__.py | 11 +++++++++-- tests/compute/docker/test_docker.py | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/gns3server/compute/docker/__init__.py b/gns3server/compute/docker/__init__.py index c75f2a86c..bbe589626 100644 --- a/gns3server/compute/docker/__init__.py +++ b/gns3server/compute/docker/__init__.py @@ -396,10 +396,17 @@ class Docker(BaseManager): params={"fromImage": image}, timeout=aiohttp.ClientTimeout(total=None, sock_read=PULL_IDLE_TIMEOUT), ) + except DockerHttp404Error as e: + raise DockerError( + f"Could not pull the '{image}' image: it was not found in the registry. " + f"Check the image name or run 'docker login' on the compute host " + f"(original error: {e})" + ) except DockerError as e: raise DockerError( - f"Could not pull the '{image}' image from Docker repository, " - f"please check your Internet connection (original error: {e})" + f"Could not pull the '{image}' image from Docker repository. " + f"Check the image name, the registry authentication and your Internet connection " + f"(original error: {e})" ) # The pull api will stream status via an HTTP JSON stream content = "" diff --git a/tests/compute/docker/test_docker.py b/tests/compute/docker/test_docker.py index 71636d04d..721c06dee 100644 --- a/tests/compute/docker/test_docker.py +++ b/tests/compute/docker/test_docker.py @@ -259,6 +259,24 @@ async def test_pull_image_error(): response.close.assert_called_once() +@pytest.mark.asyncio +async def test_pull_image_not_found_is_not_reported_as_a_network_error(): + """ + A 404 from the registry means the image name is wrong or the registry needs + authentication: telling the user to check the Internet connection sends + them in the wrong direction. + """ + + with asyncio_patch("gns3server.compute.docker.Docker.query", side_effect=DockerHttp404Error("404")): + with asyncio_patch( + "gns3server.compute.docker.Docker.http_query", + side_effect=DockerHttp404Error("Docker has returned an error: 404 pull access denied for debian13"), + ): + with pytest.raises(DockerError, match="not found in the registry") as error: + await Docker.instance().pull_image("debian13") + assert "Internet connection" not in str(error.value) + + @pytest.mark.asyncio async def test_pull_image_rejects_incomplete_response():