Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15443348
D20556.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D20556.diff
View Options
diff --git a/src/console/PhutilInteractiveEditor.php b/src/console/PhutilInteractiveEditor.php
--- a/src/console/PhutilInteractiveEditor.php
+++ b/src/console/PhutilInteractiveEditor.php
@@ -76,6 +76,32 @@
$err = $this->invokeEditor($editor, $path, $offset);
+ if ($err) {
+ // See T13297. On macOS, "vi" and "vim" may exit with errors even though
+ // the edit succeeded. If the binary is "vi" or "vim" and we get an exit
+ // code, we perform an additional test on the binary.
+ $vi_binaries = array(
+ 'vi' => true,
+ 'vim' => true,
+ );
+
+ $binary = basename($editor);
+ if (isset($vi_binaries[$binary])) {
+ // This runs "Q" (an invalid command), then "q" (a valid command,
+ // meaning "quit"). Vim binaries with behavior that makes them poor
+ // interactive editors will exit "1".
+ list($diagnostic_err) = exec_manual('%R +Q +q', $binary);
+
+ // If we get an error back, the binary is badly behaved. Ignore the
+ // original error and assume it's not meaningful, since it just
+ // indicates the user made a typo in a command when editing
+ // interactively, which is routine and unconcerning.
+ if ($diagnostic_err) {
+ $err = 0;
+ }
+ }
+ }
+
if ($err) {
Filesystem::remove($tmp);
throw new Exception(pht('Editor exited with an error code (#%d).', $err));
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mar 28 2025, 3:55 AM (6 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7436411
Default Alt Text
D20556.diff (1 KB)
Attached To
Mode
D20556: If "vi" or "vim" exit with an error code, test for error-on-interactive-mistake behavior
Attached
Detach File
Event Timeline
Log In to Comment