Skip to content

[rejected AI] fix(edit): resolve editor command via shutil.which before launching - #3874

Closed
okxint wants to merge 1 commit into
pallets:mainfrom
okxint:fix/edit-resolve-editor-via-which
Closed

okxint wants to merge 1 commit into
pallets:mainfrom
okxint:fix/edit-resolve-editor-via-which

Conversation

@okxint

@okxint okxint commented Sep 16, 2026

Copy link
Copy Markdown

Fixes #3840.

Problem

click.edit() passes the bare editor name directly to subprocess.Popen without resolving it to a full path. On Windows 11 some commands (e.g. the Store-app notepad redirect) only launch correctly via their absolute path, causing WinError 87 or WinError 14001.

Fix

Call shutil.which() on the first token of the editor command and substitute the result when found — the same pattern the pager code already uses in _resolve_pager_command. When shutil.which() returns None the original token is kept, preserving existing behaviour.

Tests

  • Updated test_editor_path_normalization to mock shutil.which (the test focuses on argument splitting, not path resolution)
  • Added test_editor_resolves_command_via_which — verifies the resolved path is used as args[0]
  • Added test_editor_keeps_command_when_which_returns_none — verifies fallback when not on PATH

edit_files() passed the bare editor name directly to subprocess.Popen
without resolving it to a full path first.  On Windows 11 some commands
(e.g. the Store-app notepad redirect) only launch correctly when invoked
via their absolute path, causing WinError 87 or WinError 14001.

The pager code already does this correctly via _resolve_pager_command.
Apply the same pattern in edit_files(): call shutil.which() on the first
token of the editor command, and substitute the result when found.  When
shutil.which() returns None (command not on PATH), the original token is
kept as-is, preserving the existing behaviour.

Fixes pallets#3840
@davidism

Copy link
Copy Markdown
Member

@davidism davidism closed this Sep 16, 2026
@davidism davidism added the rejected AI Contribution rejected because of its untrustworthy AI origin label Sep 16, 2026
@davidism davidism changed the title fix(edit): resolve editor command via shutil.which before launching [rejected AI] fix(edit): resolve editor command via shutil.which before launching Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rejected AI Contribution rejected because of its untrustworthy AI origin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

click.edit on Windows throws WinError 14001 or 87

2 participants