emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/reformatter 2ff029f84b 64/81: Display error message in err


From: ELPA Syncer
Subject: [nongnu] elpa/reformatter 2ff029f84b 64/81: Display error message in error buffer if call-process signals
Date: Tue, 5 Sep 2023 04:03:38 -0400 (EDT)

branch: elpa/reformatter
commit 2ff029f84b9afe3665d828b4b1c19f349a37c982
Author: Aaron L. Zeng <me@bcc32.com>
Commit: Aaron L. Zeng <me@bcc32.com>

    Display error message in error buffer if call-process signals
    
    `call-process` may signal instead of returning an integer code if
    executing the program failed, for example if the command was not
    found.
    
    In the case where reformatter is invoked from a `before-save-hook`,
    the only sign that anything went wrong is a line in *Messages*:
    
        Error: (file-missing "Searching for program" "No such file or 
directory" "shfmt")
    
    Unfortunately, this error message is immediately cleared from the echo
    area by the following message:
    
        Wrote /path/to/file
    
    So the user may not even know that the formatter failed to run.
    
    Change `reformatter--do-region` so that it displays the error message,
    which would have been displayed in the echo area, in the error buffer
    instead.
---
 reformatter.el | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/reformatter.el b/reformatter.el
index 73d7cddb39..b54dcb5761 100644
--- a/reformatter.el
+++ b/reformatter.el
@@ -102,17 +102,21 @@ the `reformatter-define' macro."
           (write-region beg end input-file nil :quiet)
           (let* ((error-buffer (get-buffer-create (format "*%s errors*" name)))
                  (retcode
-                  (apply 'call-process program
-                         (when stdin input-file)
-                         (list (list :file stdout-file) stderr-file)
-                         nil
-                         args)))
+                  (condition-case e
+                      (apply 'call-process program
+                                  (when stdin input-file)
+                                  (list (list :file stdout-file) stderr-file)
+                                  nil
+                                  args)
+                    (error e))))
             (with-current-buffer error-buffer
               (let ((inhibit-read-only t))
                 (insert-file-contents stderr-file nil nil nil t)
+                (unless (integerp retcode)
+                  (insert (error-message-string retcode)))
                 (ansi-color-apply-on-region (point-min) (point-max)))
               (special-mode))
-            (if (funcall exit-code-success-p retcode)
+            (if (and (integerp retcode) (funcall exit-code-success-p retcode))
                 (progn
                   (save-restriction
                     ;; This replacement method minimises



reply via email to

[Prev in Thread] Current Thread [Next in Thread]