ui: Gracefully report failures to connect to the daemon.
* guix/store.scm (&nix-connection-error): New condition type. (open-connection): Translate `system-error' during the `connect' call into `&nix-connection-error'. * guix/ui.scm (call-with-error-handling): Add case for `nix-connection-error?'. * guix/scripts/package.scm (guix-package): Move `open-connection' call within `with-error-handling'. * guix/scripts/pull.scm (guix-pull): Likewise. * guix/scripts/download.scm (guix-download): Move body within `with-error-handling'.
This commit is contained in:
parent
1fb78cb2c3
commit
ef86c39f27
|
@ -110,26 +110,27 @@ and the hash of its contents.\n"))
|
||||||
(alist-cons 'argument arg result))
|
(alist-cons 'argument arg result))
|
||||||
%default-options))
|
%default-options))
|
||||||
|
|
||||||
(let* ((opts (parse-options))
|
(with-error-handling
|
||||||
(store (open-connection))
|
(let* ((opts (parse-options))
|
||||||
(arg (assq-ref opts 'argument))
|
(store (open-connection))
|
||||||
(uri (or (string->uri arg)
|
(arg (assq-ref opts 'argument))
|
||||||
(leave (_ "guix-download: ~a: failed to parse URI~%")
|
(uri (or (string->uri arg)
|
||||||
arg)))
|
(leave (_ "guix-download: ~a: failed to parse URI~%")
|
||||||
(path (case (uri-scheme uri)
|
arg)))
|
||||||
((file)
|
(path (case (uri-scheme uri)
|
||||||
(add-to-store store (basename (uri-path uri))
|
((file)
|
||||||
#f "sha256" (uri-path uri)))
|
(add-to-store store (basename (uri-path uri))
|
||||||
(else
|
#f "sha256" (uri-path uri)))
|
||||||
(fetch-and-store store
|
(else
|
||||||
(cut url-fetch arg <>
|
(fetch-and-store store
|
||||||
#:mirrors %mirrors)
|
(cut url-fetch arg <>
|
||||||
(basename (uri-path uri))))))
|
#:mirrors %mirrors)
|
||||||
(hash (call-with-input-file
|
(basename (uri-path uri))))))
|
||||||
(or path
|
(hash (call-with-input-file
|
||||||
(leave (_ "guix-download: ~a: download failed~%")
|
(or path
|
||||||
arg))
|
(leave (_ "guix-download: ~a: download failed~%")
|
||||||
(compose sha256 get-bytevector-all)))
|
arg))
|
||||||
(fmt (assq-ref opts 'format)))
|
(compose sha256 get-bytevector-all)))
|
||||||
(format #t "~a~%~a~%" path (fmt hash))
|
(fmt (assq-ref opts 'format)))
|
||||||
#t))
|
(format #t "~a~%~a~%" path (fmt hash))
|
||||||
|
#t)))
|
||||||
|
|
|
@ -712,8 +712,8 @@ Install, remove, or upgrade PACKAGES in a single transaction.\n"))
|
||||||
|
|
||||||
(let ((opts (parse-options)))
|
(let ((opts (parse-options)))
|
||||||
(or (process-query opts)
|
(or (process-query opts)
|
||||||
(parameterize ((%store (open-connection)))
|
(with-error-handling
|
||||||
(with-error-handling
|
(parameterize ((%store (open-connection)))
|
||||||
(parameterize ((%guile-for-build
|
(parameterize ((%guile-for-build
|
||||||
(package-derivation (%store)
|
(package-derivation (%store)
|
||||||
(if (assoc-ref opts 'bootstrap?)
|
(if (assoc-ref opts 'bootstrap?)
|
||||||
|
|
|
@ -194,9 +194,9 @@ Download and deploy the latest version of Guix.\n"))
|
||||||
(leave (_ "~A: unexpected argument~%") arg))
|
(leave (_ "~A: unexpected argument~%") arg))
|
||||||
%default-options))
|
%default-options))
|
||||||
|
|
||||||
(let ((opts (parse-options))
|
(with-error-handling
|
||||||
(store (open-connection)))
|
(let ((opts (parse-options))
|
||||||
(with-error-handling
|
(store (open-connection)))
|
||||||
(let ((tarball (download-and-store store)))
|
(let ((tarball (download-and-store store)))
|
||||||
(unless tarball
|
(unless tarball
|
||||||
(leave (_ "failed to download up-to-date source, exiting\n")))
|
(leave (_ "failed to download up-to-date source, exiting\n")))
|
||||||
|
|
|
@ -39,6 +39,9 @@
|
||||||
nix-server-socket
|
nix-server-socket
|
||||||
|
|
||||||
&nix-error nix-error?
|
&nix-error nix-error?
|
||||||
|
&nix-connection-error nix-connection-error?
|
||||||
|
nix-connection-error-file
|
||||||
|
nix-connection-error-code
|
||||||
&nix-protocol-error nix-protocol-error?
|
&nix-protocol-error nix-protocol-error?
|
||||||
nix-protocol-error-message
|
nix-protocol-error-message
|
||||||
nix-protocol-error-status
|
nix-protocol-error-status
|
||||||
|
@ -373,6 +376,11 @@
|
||||||
(define-condition-type &nix-error &error
|
(define-condition-type &nix-error &error
|
||||||
nix-error?)
|
nix-error?)
|
||||||
|
|
||||||
|
(define-condition-type &nix-connection-error &nix-error
|
||||||
|
nix-connection-error?
|
||||||
|
(file nix-connection-error-file)
|
||||||
|
(errno nix-connection-error-code))
|
||||||
|
|
||||||
(define-condition-type &nix-protocol-error &nix-error
|
(define-condition-type &nix-protocol-error &nix-error
|
||||||
nix-protocol-error?
|
nix-protocol-error?
|
||||||
(message nix-protocol-error-message)
|
(message nix-protocol-error-message)
|
||||||
|
@ -392,7 +400,15 @@ operate, should the disk become full. Return a server object."
|
||||||
;; Enlarge the receive buffer.
|
;; Enlarge the receive buffer.
|
||||||
(setsockopt s SOL_SOCKET SO_RCVBUF (* 12 1024))
|
(setsockopt s SOL_SOCKET SO_RCVBUF (* 12 1024))
|
||||||
|
|
||||||
(connect s a)
|
(catch 'system-error
|
||||||
|
(cut connect s a)
|
||||||
|
(lambda args
|
||||||
|
;; Translate the error to something user-friendly.
|
||||||
|
(let ((errno (system-error-errno args)))
|
||||||
|
(raise (condition (&nix-connection-error
|
||||||
|
(file file)
|
||||||
|
(errno errno)))))))
|
||||||
|
|
||||||
(write-int %worker-magic-1 s)
|
(write-int %worker-magic-1 s)
|
||||||
(let ((r (read-int s)))
|
(let ((r (read-int s)))
|
||||||
(and (eqv? r %worker-magic-2)
|
(and (eqv? r %worker-magic-2)
|
||||||
|
|
|
@ -111,6 +111,10 @@ General help using GNU software: <http://www.gnu.org/gethelp/>"))
|
||||||
(leave (_ "~a:~a:~a: error: package `~a' has an invalid input: ~s~%")
|
(leave (_ "~a:~a:~a: error: package `~a' has an invalid input: ~s~%")
|
||||||
file line column
|
file line column
|
||||||
(package-full-name package) input)))
|
(package-full-name package) input)))
|
||||||
|
((nix-connection-error? c)
|
||||||
|
(leave (_ "error: failed to connect to `~a': ~a~%")
|
||||||
|
(nix-connection-error-file c)
|
||||||
|
(strerror (nix-connection-error-code c))))
|
||||||
((nix-protocol-error? c)
|
((nix-protocol-error? c)
|
||||||
;; FIXME: Server-provided error messages aren't i18n'd.
|
;; FIXME: Server-provided error messages aren't i18n'd.
|
||||||
(leave (_ "error: build failed: ~a~%")
|
(leave (_ "error: build failed: ~a~%")
|
||||||
|
|
Loading…
Reference in New Issue