]> git.eshelyaron.com Git - emacs.git/commitdiff
Return non-zero exit status when Eshell's "which" fails to find a command
authorJim Porter <jporterbugs@gmail.com>
Mon, 9 Dec 2024 04:21:31 +0000 (20:21 -0800)
committerEshel Yaron <me@eshelyaron.com>
Mon, 9 Dec 2024 12:50:19 +0000 (13:50 +0100)
* lisp/eshell/esh-cmd.el (eshell/which): Set exit status to 1 if we
couldn't find any of the commands (bug#74739).

(cherry picked from commit b6c91cdf54168eef260e28a7866486a4d68bfc9e)

lisp/eshell/esh-cmd.el

index 4b7061c0e01c44c152b31fa3424a3e6fef0e9329..0927fd8f08740f14922ce2e9bceff8f074039227 100644 (file)
@@ -1381,19 +1381,22 @@ have been replaced by constants."
 
 (defun eshell/which (command &rest names)
   "Identify the COMMAND, and where it is located."
-  (dolist (name (cons command names))
-    (condition-case error
-        (eshell-printn
-         (catch 'found
-           (run-hook-wrapped
-            'eshell-named-command-hook
-            (lambda (hook)
-              (when-let (((symbolp hook))
-                         (which-func (get hook 'eshell-which-function))
-                         (result (funcall which-func command)))
-                (throw 'found result))))
-           (eshell-plain-command--which name)))
-      (error (eshell-error (format "which: %s\n" (cadr error)))))))
+  (let (not-found)
+    (dolist (name (cons command names))
+      (condition-case error
+          (eshell-printn
+           (catch 'found
+             (run-hook-wrapped
+              'eshell-named-command-hook
+              (lambda (hook)
+                (when-let* (((symbolp hook))
+                            (which-func (get hook 'eshell-which-function))
+                            (result (funcall which-func command)))
+                  (throw 'found result))))
+             (eshell-plain-command--which name)))
+        (error (eshell-error (format "which: %s\n" (cadr error)))
+               (setq not-found t))))
+    (when not-found (eshell-set-exit-info 1))))
 
 (put 'eshell/which 'eshell-no-numeric-conversions t)