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

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

[nongnu] elpa/go-mode b36d2fd 352/495: cmd/guru: emacs: report an error


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode b36d2fd 352/495: cmd/guru: emacs: report an error when the guru command fails
Date: Sat, 7 Aug 2021 09:05:46 -0400 (EDT)

branch: elpa/go-mode
commit b36d2fd65b1e2c86501c1ddad39c0f297d8a34c9
Author: Alan Donovan <alan@alandonovan.net>
Commit: Dominik Honnef <dominik@honnef.co>

    cmd/guru: emacs: report an error when the guru command fails
    
    Don't just display the output buffer or, worse, parse it as JSON.
    
    Change-Id: I1125ff235a5073b07f45f587ef8844b8a12f05ac
    Reviewed-on: https://go-review.googlesource.com/19508
    Reviewed-by: Michael Matloob <matloob@golang.org>
---
 guru_import/cmd/guru/guru.el | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/guru_import/cmd/guru/guru.el b/guru_import/cmd/guru/guru.el
index 137d35e..619b8db 100644
--- a/guru_import/cmd/guru/guru.el
+++ b/guru_import/cmd/guru/guru.el
@@ -127,14 +127,21 @@ a scope if not already set.  Return the output buffer."
        (message nil) ; clears/shrinks minibuffer
        (message "Running guru...")
        ;; Use dynamic binding to modify/restore the environment
-       (let ((process-environment (list* goroot-env gopath-env 
process-environment)))
-         (apply #'call-process-region (append (list (point-min)
-                                                    (point-max)
-                                                    go-guru-command
-                                                    nil ; delete
-                                                    output-buffer
-                                                    t)
-                                              args)))))
+       (let* ((process-environment (list* goroot-env gopath-env 
process-environment))
+              (c-p-args (append (list (point-min)
+                                      (point-max)
+                                      go-guru-command
+                                      nil ; delete
+                                      output-buffer
+                                      t)
+                                args))
+              (exitcode (apply #'call-process-region c-p-args)))
+         ;; If the command fails, don't show the output buffer,
+         ;; but use its contents (sans final \n) as an error.
+         (unless (zerop exitcode)
+           (with-current-buffer output-buffer
+             (bury-buffer)
+             (error "%s" (buffer-substring (point-min) (1- (point-max)))))))))
     output-buffer))
 
 (defun go-guru--compilation-markup ()
@@ -227,8 +234,8 @@ function containing the current point."
   ;; TODO(adonovan): use -format=sexpr when available to avoid a
   ;; dependency and to simplify parsing.
   (let* ((res (with-current-buffer (go-guru--exec "definition" nil 
'("-format=json"))
-              (goto-char (point-min))
-              (cdr (car (json-read)))))
+               (goto-char (point-min))
+               (cdr (car (json-read)))))
         (desc (cdr (assoc 'desc res))))
     (go-guru--goto-pos (cdr (assoc 'objpos res)))
     (message "%s" desc)))



reply via email to

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