diff --git a/news/10812.feature.rst b/news/10812.feature.rst new file mode 100644 index 00000000000..a8fbc37d9aa --- /dev/null +++ b/news/10812.feature.rst @@ -0,0 +1,2 @@ +Improve error message when ``pip config edit`` is provided an editor that +doesn't exist. diff --git a/src/pip/_internal/commands/configuration.py b/src/pip/_internal/commands/configuration.py index c6c74ed50ba..941ee87b5e0 100644 --- a/src/pip/_internal/commands/configuration.py +++ b/src/pip/_internal/commands/configuration.py @@ -225,6 +225,10 @@ def open_in_editor(self, options: Values, args: List[str]) -> None: try: subprocess.check_call([editor, fname]) + except FileNotFoundError as e: + if not e.filename: + e.filename = editor + raise except subprocess.CalledProcessError as e: raise PipError( "Editor Subprocess exited with exit code {}".format(e.returncode) diff --git a/tests/functional/test_configuration.py b/tests/functional/test_configuration.py index 9f656287507..b3de3f697b0 100644 --- a/tests/functional/test_configuration.py +++ b/tests/functional/test_configuration.py @@ -140,3 +140,10 @@ def test_global_config_file(self, script: PipTestEnvironment) -> None: global_config_file = get_configuration_files()[kinds.GLOBAL][0] result = script.pip("config", "debug") assert f"{global_config_file}, exists:" in result.stdout + + def test_editor_does_not_exist(self, script: PipTestEnvironment) -> None: + """Ensure that FileNotFoundError sets filename correctly""" + result = script.pip( + "config", "edit", "--editor", "notrealeditor", expect_error=True + ) + assert "notrealeditor" in result.stderr