`click.edit` on Windows throws WinError 14001 or 87
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.7k
- Forks
- 2.3k
- Avg merge
- 1d 30m
- Merged PRs (30d)
- 18
Description
I found this bug while testing my own Click application. In about half the times click.edit() is attempted on Windows, notepad.exe will fail to launch with one of these two error messages (output under spoilers):
OSError: [WinError 87] The parameter is incorrect
PS C:\Users\Emory> python .\click-notepad-me.py
Traceback (most recent call last):
File "C:\Users\Emory\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\click\_termui_impl.py", line 729, in edit_files
c = subprocess.Popen(
args=shlex.split(editor) + list(filenames),
env=environ,
)
File "C:\Users\Emory\AppData\Local\Python\pythoncore-3.14-64\Lib\subprocess.py", line 1038, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pass_fds, cwd, env,
^^^^^^^^^^^^^^^^^^^
...<5 lines>...
gid, gids, uid, umask,
^^^^^^^^^^^^^^^^^^^^^^
start_new_session, process_group)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Emory\AppData\Local\Python\pythoncore-3.14-64\Lib\subprocess.py", line 1552, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
# no special security
^^^^^^^^^^^^^^^^^^^^^
...<4 lines>...
cwd,
^^^^
startupinfo)
^^^^^^^^^^^^
OSError: [WinError 87] The parameter is incorrect
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Emory\click-notepad-me.py", line 3, in <module>
_ = click.edit()
File "C:\Users\Emory\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\click\termui.py", line 904, in edit
return ed.edit(text)
~~~~~~~^^^^^^
File "C:\Users\Emory\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\click\_termui_impl.py", line 783, in edit
self.edit_files((name,))
~~~~~~~~~~~~~~~^^^^^^^^^
File "C:\Users\Emory\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\click\_termui_impl.py", line 739, in edit_files
raise ClickException(
_("{editor}: Editing failed: {e}").format(editor=editor, e=e)
) from e
click.exceptions.ClickException: notepad: Editing failed: [WinError 87] The parameter is incorrect
or
OSError: [WinError 14001] The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail
PS C:\Users\Emory> python .\click-notepad-me.py
Traceback (most recent call last):
File "C:\Users\Emory\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\click\_termui_impl.py", line 729, in edit_files
c = subprocess.Popen(
args=shlex.split(editor) + list(filenames),
env=environ,
)
File "C:\Users\Emory\AppData\Local\Python\pythoncore-3.14-64\Lib\subprocess.py", line 1038, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pass_fds, cwd, env,
^^^^^^^^^^^^^^^^^^^
...<5 lines>...
gid, gids, uid, umask,
^^^^^^^^^^^^^^^^^^^^^^
start_new_session, process_group)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Emory\AppData\Local\Python\pythoncore-3.14-64\Lib\subprocess.py", line 1552, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
# no special security
^^^^^^^^^^^^^^^^^^^^^
...<4 lines>...
cwd,
^^^^
startupinfo)
^^^^^^^^^^^^
OSError: [WinError 14001] The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Emory\click-notepad-me.py", line 3, in <module>
_ = click.edit()
File "C:\Users\Emory\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\click\termui.py", line 904, in edit
return ed.edit(text)
~~~~~~~^^^^^^
File "C:\Users\Emory\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\click\_termui_impl.py", line 783, in edit
self.edit_files((name,))
~~~~~~~~~~~~~~~^^^^^^^^^
File "C:\Users\Emory\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\click\_termui_impl.py", line 739, in edit_files
raise ClickException(
_("{editor}: Editing failed: {e}").format(editor=editor, e=e)
) from e
click.exceptions.ClickException: notepad: Editing failed: [WinError 14001] The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail
To replicate, run this script until you get one of these:
import click
_ = click.edit()
print("If you got here, no crash occurred")
Environment:
- Python version: 3.12.14 / also reproduced on my system 3.14 install
- Click version: 8.5.0
- OS: Windows 11 (64-bit)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with click/_termui_impl.py, especially edit_files, and reproduce the failure by repeatedly running the provided click.edit() script on Windows. Trace how the editor command is passed to subprocess.Popen; done means click.edit() reliably launches notepad.exe without WinError 87 or 14001.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100