summary refs log tree commit diff
path: root/guix-download.in
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2012-11-13 22:13:11 +0100
committerLudovic Courtès <ludo@gnu.org>2012-11-13 22:15:59 +0100
commitecdb81e159a29c92351bc51c3556a760074f7473 (patch)
treef7113a1036729caab5fef32fd783b7b984b91898 /guix-download.in
parentdb32c281dd8c74b938119048d63090e84fb4ebe0 (diff)
downloadguix-ecdb81e159a29c92351bc51c3556a760074f7473.tar.gz
guix-download: Gracefully handle invalid URIs.
* guix-download.in (guix-download): Error out when `string->uri'
  returns #f.  Use `leave' when the scheme is unknown.
* tests/guix-download.sh: Add tests.
Diffstat (limited to 'guix-download.in')
-rw-r--r--guix-download.in11
1 files changed, 5 insertions, 6 deletions
diff --git a/guix-download.in b/guix-download.in
index 46efaa17e8..a3fd4b55d4 100644
--- a/guix-download.in
+++ b/guix-download.in
@@ -159,16 +159,15 @@ Report bugs to: ~a.~%") "@PACKAGE_BUGREPORT@"))
 
   (let* ((opts  (parse-options))
          (store (open-connection))
-         (uri   (string->uri (assq-ref opts 'argument)))
+         (uri   (or (string->uri (assq-ref opts 'argument))
+                    (leave (_ "guix-download: ~a: failed to parse URI~%")
+                           (assq-ref opts 'argument))))
          (fetch (case (uri-scheme uri)
                   ((http) http-fetch)
                   ((ftp)  ftp-fetch)
                   (else
-                   (begin
-                     (format (current-error-port)
-                             (_ "guix-download: ~a: unsupported URI scheme~%")
-                             (uri-scheme uri))
-                     (exit 1)))))
+                   (leave (_ "guix-download: ~a: unsupported URI scheme~%")
+                          (uri-scheme uri)))))
          (path  (call-with-temporary-output-file
                  (lambda (name port)
                    (fetch uri port)