From ec5d0a85ebdac90f627bfdf0367623eeb88a85af Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
Date: Fri, 10 May 2013 12:14:01 +0200
Subject: [PATCH] ui: Gracefully report "command not found" errors.

* guix/ui.scm (run-guix-command): Can `resolve-interface' errors and
  report them with `leave'.  Parameterize `program-name' from here.
  (guix-main): Remove parameterization of `program-name'.
---
 guix/ui.scm | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/guix/ui.scm b/guix/ui.scm
index cd32bfe079d..1435575cdd2 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -389,17 +389,25 @@ (define (show-guix-usage)
   (format (current-error-port)
           (_ "Usage: guix COMMAND ARGS...~%")))
 
-(define (run-guix-command command . args)
-  ;; TODO: Gracefully report errors
-  (let* ((module (resolve-interface `(guix scripts ,command)))
-         (command-main (module-ref module
-                                   (symbol-append 'guix- command))))
-    (apply command-main args)))
-
 (define program-name
   ;; Name of the command-line program currently executing, or #f.
   (make-parameter #f))
 
+(define (run-guix-command command . args)
+  "Run COMMAND with the given ARGS.  Report an error when COMMAND is not
+found."
+  (define module
+    (catch 'misc-error
+      (lambda ()
+        (resolve-interface `(guix scripts ,command)))
+      (lambda -
+        (leave (_ "~a: command not found~%") command))))
+
+  (let ((command-main (module-ref module
+                                  (symbol-append 'guix- command))))
+    (parameterize ((program-name command))
+      (apply command-main args))))
+
 (define guix-warning-port
   (make-parameter (current-warning-port)))
 
@@ -413,9 +421,8 @@ (define (option? str) (string-prefix? "-" str))
       (("--version") (show-version-and-exit "guix"))
       (((? option?) args ...) (show-guix-usage) (exit 1))
       ((command args ...)
-       (parameterize ((program-name command))
-         (apply run-guix-command
-                (string->symbol command)
-                args))))))
+       (apply run-guix-command
+              (string->symbol command)
+              args)))))
 
 ;;; ui.scm ends here
-- 
GitLab