@@ -139,42 +139,18 @@ def start(self) -> 'Container':
139139 def _pull_or_get_image (self ) -> None :
140140 try :
141141 self ._docker_client .images .pull (self ._image_name , self ._image_tag )
142- except errors .APIError :
143- self ._handle_image_pull_error ()
142+ except errors .APIError as e :
143+ self ._handle_image_pull_error (e )
144144
145- def _handle_image_pull_error (self ) -> None :
145+ def _handle_image_pull_error (self , error ) -> None :
146146 image_name = f"{ self ._image_name } :{ self ._image_tag } "
147-
148- # First check if the image is already available locally
149147 try :
150148 self ._docker_client .images .get (image_name )
151149 except errors .ImageNotFound :
152- logging .info ("Image not found locally, attempting to pull: %s" , image_name )
153- else :
154- logging .info ("Using locally available image: %s" , image_name )
155- return
150+ raise RuntimeError (
151+ f'Could not pull image and no local image available: { error } ' ) from error
156152
157- # Try to pull the image
158- try :
159- # Pull image with default timeout settings
160- self ._docker_client .api .pull (
161- self ._image_name ,
162- tag = self ._image_tag )
163- except (
164- errors .APIError ,
165- requests .exceptions .Timeout ,
166- requests .exceptions .ConnectionError
167- ) as e :
168- # pylint: disable=W0717
169- try :
170- self ._docker_client .images .get (image_name )
171- logging .warning (
172- "Warning: Failed to pull image: %s. Using locally cached image." , e
173- )
174- except errors .ImageNotFound :
175- raise RuntimeError (
176- f'Could not pull image { image_name } and no local image available: { e } '
177- ) from e
153+ logging .warning ("Warning: Could not pull image: %s. Using locally cached image." , error )
178154
179155 def stop (self ) -> None :
180156 self ._stop_and_remove_container ()
0 commit comments