]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix emacsclient when there are irrecoverable file-visiting errors
authorEli Zaretskii <eliz@gnu.org>
Fri, 26 May 2023 10:20:56 +0000 (13:20 +0300)
committerEli Zaretskii <eliz@gnu.org>
Fri, 26 May 2023 10:20:56 +0000 (13:20 +0300)
* lisp/server.el (server-process-filter, server-return-error):
Display the error message to be sent to the client as a regular
message, to give the user the opportunity to see it.  Delete the
terminal immediately after sending the error message to the
client, to make sure the terminal's modes are restored.
(Bug#63629)

lisp/server.el

index 608e5df3a5b332bba59a9b2cefe21658e8deec36..c3325e5a24c3737ea66c5f4077a2e16ad7fe6692 100644 (file)
@@ -1143,8 +1143,18 @@ The following commands are accepted by the client:
          (process-put proc :authenticated t)
          (server-log "Authentication successful" proc))
       (server-log "Authentication failed" proc)
+      ;; Display the error as a message and give the user time to see
+      ;; it, in case the error written by emacsclient to stderr is not
+      ;; visible for some reason.
+      (message "Authentication failed")
+      (sit-for 2)
       (server-send-string
        proc (concat "-error " (server-quote-arg "Authentication failed")))
+      (unless (eq system-type 'windows-nt)
+        (let ((terminal (process-get proc 'terminal)))
+          ;; Only delete the terminal if it is non-nil.
+          (when (and terminal (eq (terminal-live-p terminal) t))
+           (delete-terminal terminal))))
       ;; Before calling `delete-process', give emacsclient time to
       ;; receive the error string and shut down on its own.
       (sit-for 1)
@@ -1462,10 +1472,20 @@ The following commands are accepted by the client:
 
 (defun server-return-error (proc err)
   (ignore-errors
+    ;; Display the error as a message and give the user time to see
+    ;; it, in case the error written by emacsclient to stderr is not
+    ;; visible for some reason.
+    (message (error-message-string err))
+    (sit-for 2)
     (server-send-string
      proc (concat "-error " (server-quote-arg
                              (error-message-string err))))
     (server-log (error-message-string err) proc)
+    (unless (eq system-type 'windows-nt)
+      (let ((terminal (process-get proc 'terminal)))
+        ;; Only delete the terminal if it is non-nil.
+        (when (and terminal (eq (terminal-live-p terminal) t))
+         (delete-terminal terminal))))
     ;; Before calling `delete-process', give emacsclient time to
     ;; receive the error string and shut down on its own.
     (sit-for 5)