Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a better error message if a file: URL is not found #10263

Merged
merged 37 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
752c4f9
Return a better error message if a file is not found
DiddiLeija Aug 2, 2021
5afb103
Create 10263.bugfix.rst
DiddiLeija Aug 2, 2021
6854c25
Format the error message
DiddiLeija Aug 2, 2021
d1c19ed
Fix an ImportError
DiddiLeija Aug 2, 2021
4473870
Adjust the error message
DiddiLeija Aug 5, 2021
f0086ac
Update the error message
DiddiLeija Aug 5, 2021
538fb0d
Update the error message
DiddiLeija Aug 6, 2021
1b674e6
Update the error message
DiddiLeija Aug 6, 2021
1a0fb42
Create test_bad_url.py
DiddiLeija Aug 16, 2021
8c72c9b
Style fixes to `test_bad_url.py`
DiddiLeija Aug 16, 2021
99a316b
Update test_bad_url.py
DiddiLeija Aug 16, 2021
1eac21e
Update test_bad_url.py
DiddiLeija Aug 16, 2021
7141432
Update test_bad_url.py
DiddiLeija Aug 16, 2021
2703119
Update test_bad_url.py
DiddiLeija Aug 16, 2021
b6e66ce
Update test_bad_url.py
DiddiLeija Aug 16, 2021
fa03122
Update test_bad_url.py
DiddiLeija Aug 16, 2021
b3a62af
Update test_bad_url.py
DiddiLeija Aug 16, 2021
4f6eb30
Update test_bad_url.py
DiddiLeija Aug 16, 2021
aceefdc
Update test_bad_url.py
DiddiLeija Aug 16, 2021
de0452f
Update test_bad_url.py
DiddiLeija Aug 17, 2021
029a113
Update test_bad_url.py
DiddiLeija Aug 17, 2021
51274d4
Update test_bad_url.py
DiddiLeija Aug 17, 2021
12971f4
Update test_bad_url.py
DiddiLeija Aug 17, 2021
b7bce7c
Update test_bad_url.py
DiddiLeija Aug 17, 2021
9faf241
Update test_bad_url.py
DiddiLeija Aug 17, 2021
e7ca41e
Update test_bad_url.py
DiddiLeija Aug 17, 2021
5877fbb
Update tests/functional/test_bad_url.py
DiddiLeija Aug 17, 2021
5147c2c
Update test_bad_url.py
DiddiLeija Aug 17, 2021
086b1c0
Update test_bad_url.py
DiddiLeija Aug 17, 2021
2f1227b
Update test_bad_url.py
DiddiLeija Aug 17, 2021
48884de
Update test_bad_url.py
DiddiLeija Aug 17, 2021
e14674c
Update test_bad_url.py
DiddiLeija Aug 17, 2021
79a6507
Update test_bad_url.py
DiddiLeija Aug 19, 2021
6f0369c
Update test_bad_url.py
DiddiLeija Aug 19, 2021
37242e0
Update test_bad_url.py
DiddiLeija Sep 21, 2021
dee894b
Update news/10263.bugfix.rst
pradyunsg Oct 8, 2021
dd1103f
Update news/10263.bugfix.rst
pradyunsg Oct 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/10263.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Return better error messages if a file/URL is not found.
DiddiLeija marked this conversation as resolved.
Show resolved Hide resolved
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 5 additions & 1 deletion src/pip/_internal/network/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import email.utils
import io
import ipaddress
import json
import logging
Expand Down Expand Up @@ -207,8 +208,11 @@ def send(
try:
stats = os.stat(pathname)
except OSError as exc:
# format the exception raised as a io.BytesIO object,
# to return a better error message:
resp.status_code = 404
resp.raw = exc
resp.reason = type(exc).__name__
resp.raw = io.BytesIO(f"{resp.reason}: {exc}".encode("utf8"))
else:
modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
content_type = mimetypes.guess_type(pathname)[0] or "text/plain"
Expand Down
16 changes: 16 additions & 0 deletions tests/functional/test_bad_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# test the error message returned by pip when
# a bad "file:" URL is passed to it.

from typing import Any


def test_filenotfound_error_message(script: Any) -> None:
# Test the error message returned when using a bad 'file:' URL.
# make pip to fail and get an error message
# by running "pip install -r file:nonexistent_file"
proc = script.pip("install", "-r", "file:unexistent_file", expect_error=True)
assert proc.returncode == 1
expect = (
"ERROR: 404 Client Error: FileNotFoundError for url: file:///unexistent_file"
)
assert proc.stderr.rstrip() == expect
DiddiLeija marked this conversation as resolved.
Show resolved Hide resolved