~ruther/guix-local

ef86c39f27b0d1c21435ea54cba5fb247e341537 — Ludovic Courtès 13 years ago 1fb78cb
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'.
5 files changed, 50 insertions(+), 29 deletions(-)

M guix/scripts/download.scm
M guix/scripts/package.scm
M guix/scripts/pull.scm
M guix/store.scm
M guix/ui.scm
M guix/scripts/download.scm => guix/scripts/download.scm +24 -23
@@ 110,26 110,27 @@ and the hash of its contents.\n"))
                 (alist-cons 'argument arg result))
               %default-options))

  (let* ((opts  (parse-options))
         (store (open-connection))
         (arg   (assq-ref opts 'argument))
         (uri   (or (string->uri arg)
                    (leave (_ "guix-download: ~a: failed to parse URI~%")
                           arg)))
         (path  (case (uri-scheme uri)
                  ((file)
                   (add-to-store store (basename (uri-path uri))
                                 #f "sha256" (uri-path uri)))
                  (else
                   (fetch-and-store store
                                    (cut url-fetch arg <>
                                         #:mirrors %mirrors)
                                    (basename (uri-path uri))))))
         (hash  (call-with-input-file
                    (or path
                        (leave (_ "guix-download: ~a: download failed~%")
                               arg))
                  (compose sha256 get-bytevector-all)))
         (fmt   (assq-ref opts 'format)))
    (format #t "~a~%~a~%" path (fmt hash))
    #t))
  (with-error-handling
    (let* ((opts  (parse-options))
           (store (open-connection))
           (arg   (assq-ref opts 'argument))
           (uri   (or (string->uri arg)
                      (leave (_ "guix-download: ~a: failed to parse URI~%")
                             arg)))
           (path  (case (uri-scheme uri)
                    ((file)
                     (add-to-store store (basename (uri-path uri))
                                   #f "sha256" (uri-path uri)))
                    (else
                     (fetch-and-store store
                                      (cut url-fetch arg <>
                                           #:mirrors %mirrors)
                                      (basename (uri-path uri))))))
           (hash  (call-with-input-file
                      (or path
                          (leave (_ "guix-download: ~a: download failed~%")
                                 arg))
                    (compose sha256 get-bytevector-all)))
           (fmt   (assq-ref opts 'format)))
      (format #t "~a~%~a~%" path (fmt hash))
      #t)))

M guix/scripts/package.scm => guix/scripts/package.scm +2 -2
@@ 712,8 712,8 @@ Install, remove, or upgrade PACKAGES in a single transaction.\n"))

  (let ((opts (parse-options)))
    (or (process-query opts)
        (parameterize ((%store (open-connection)))
          (with-error-handling
        (with-error-handling
          (parameterize ((%store (open-connection)))
            (parameterize ((%guile-for-build
                            (package-derivation (%store)
                                                (if (assoc-ref opts 'bootstrap?)

M guix/scripts/pull.scm => guix/scripts/pull.scm +3 -3
@@ 194,9 194,9 @@ Download and deploy the latest version of Guix.\n"))
                 (leave (_ "~A: unexpected argument~%") arg))
               %default-options))

  (let ((opts  (parse-options))
        (store (open-connection)))
    (with-error-handling
  (with-error-handling
    (let ((opts  (parse-options))
          (store (open-connection)))
      (let ((tarball (download-and-store store)))
        (unless tarball
          (leave (_ "failed to download up-to-date source, exiting\n")))

M guix/store.scm => guix/store.scm +17 -1
@@ 39,6 39,9 @@
            nix-server-socket

            &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-message
            nix-protocol-error-status


@@ 373,6 376,11 @@
(define-condition-type &nix-error &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
  nix-protocol-error?
  (message nix-protocol-error-message)


@@ 392,7 400,15 @@ operate, should the disk become full.  Return a server object."
    ;; Enlarge the receive buffer.
    (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)
    (let ((r (read-int s)))
      (and (eqv? r %worker-magic-2)

M guix/ui.scm => guix/ui.scm +4 -0
@@ 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~%")
                      file line column
                      (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)
             ;; FIXME: Server-provided error messages aren't i18n'd.
             (leave (_ "error: build failed: ~a~%")