Skip to content

Commit e6d0301

Browse files
committed
fix(pip/_internal): Add a generic network exception to be raised
1 parent 1ebeab5 commit e6d0301

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

news/5380.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Raise user friendly errors on network failures

src/pip/_internal/cli/base_command.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
BadCommand,
2828
CommandError,
2929
InstallationError,
30+
NetworkConnectionError,
3031
PreviousBuildDirError,
3132
SubProcessError,
3233
UninstallationError,
@@ -203,7 +204,7 @@ def _main(self, args):
203204

204205
return PREVIOUS_BUILD_DIR_ERROR
205206
except (InstallationError, UninstallationError, BadCommand,
206-
SubProcessError) as exc:
207+
SubProcessError, NetworkConnectionError) as exc:
207208
logger.critical(str(exc))
208209
logger.debug('Exception information:', exc_info=True)
209210

src/pip/_internal/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ class PreviousBuildDirError(PipError):
9393
"""Raised when there's a previous conflicting build directory"""
9494

9595

96+
class NetworkConnectionError(PipError):
97+
"""HTTP connection error"""
98+
99+
96100
class InvalidWheelFilename(InstallationError):
97101
"""Invalid wheel filename."""
98102

src/pip/_internal/network/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from pip._vendor.requests.models import CONTENT_CHUNK_SIZE, Response
2+
from pip._vendor.urllib3.exceptions import NewConnectionError, ReadTimeoutError
23

4+
from pip._internal.exceptions import NetworkConnectionError
35
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
46

57
if MYPY_CHECK_RUNNING:
@@ -46,3 +48,8 @@ def response_chunks(response, chunk_size=CONTENT_CHUNK_SIZE):
4648
if not chunk:
4749
break
4850
yield chunk
51+
except (NewConnectionError, ReadTimeoutError) as exc:
52+
raise NetworkConnectionError(
53+
"Failed to get address for host! Check your network connectivity "
54+
"and DNS settings.\nDetails: {}".format(exc)
55+
)

0 commit comments

Comments
 (0)