Skip to content

Improve error message when using non local file URIs #11577

Open
@froli-code

Description

@froli-code

Description

Issue created as a successor to #6247

If an URI contains a reference to a remote host (e.g. file://myfoo/ ) the following error message is provided:
ValueError: non-local file URIs are not supported on this platform: 'file://myfoo/'

Expected behavior

While the error-message is correct, it could be improved in order to explain the behavior and suggest a solution to the user.
It is quite likely that the user wanted to use a local file, and not a file located on a remote host.

The following error message is suggested:
'file://myfoo/' points to the domain 'myfoo'. Non-local file URIs are not supported on this platform. Did you mean to use 'file:/myfoo/'?

In version 22.3 the stack-trace is included in the error message as well. I don't think that this is needed, since the error message above would explain the issue.

pip version

22.3

Python version

3.10

OS

Manjaro 22.0.0

How to Reproduce

# requirements.txt
myfoo
# constraints.txt
file://myfoo/

$ pip install -r requirements.txt -c constraints.txt

Output

ERROR: Exception:
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 160, in exc_logging_wrapper
    status = run_func(*args)
  File "/usr/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 247, in wrapper
    return func(self, options, args)
  File "/usr/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 344, in run
    reqs = self.get_requirements(args, options, finder, session)
  File "/usr/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 403, in get_requirements
    req_to_add = install_req_from_parsed_requirement(
  File "/usr/lib/python3.10/site-packages/pip/_internal/req/constructors.py", line 471, in install_req_from_parsed_requirement
    req = install_req_from_line(
  File "/usr/lib/python3.10/site-packages/pip/_internal/req/constructors.py", line 395, in install_req_from_line
    return InstallRequirement(
  File "/usr/lib/python3.10/site-packages/pip/_internal/req/req_install.py", line 127, in __init__
    self.local_file_path = self.link.file_path
  File "/usr/lib/python3.10/site-packages/pip/_internal/models/link.py", line 330, in file_path
    return url_to_path(self.url)
  File "/usr/lib/python3.10/site-packages/pip/_internal/utils/urls.py", line 43, in url_to_path
    raise ValueError(
ValueError: non-local file URIs are not supported on this platform: 'file://myfoo/'

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions