substitute-binary: Gracefully exit upon networking errors.

Suggested by Andreas Enge <andreas@enge.fr>.

* guix/scripts/substitute-binary.scm (with-networking): New macro.
  (guix-substitute-binary): Wrap the body in `with-networking'.
This commit is contained in:
Ludovic Courtès 2013-05-29 23:21:54 +02:00
parent 56b1f4b780
commit cf5d2ca329

View file

@ -361,6 +361,19 @@ (define %cache-url
(or (getenv "GUIX_BINARY_SUBSTITUTE_URL")
"http://hydra.gnu.org"))
(define-syntax with-networking
(syntax-rules ()
"Catch DNS lookup errors and gracefully exit."
;; Note: no attempt is made to catch other networking errors, because DNS
;; lookup errors are typically the first one, and because other errors are
;; a subset of `system-error', which is harder to filter.
((_ exp ...)
(catch 'getaddrinfo-error
(lambda () exp ...)
(lambda (key error)
(leave (_ "host name lookup error: ~a~%")
(gai-strerror error)))))))
;;;
;;; Entry point.
@ -370,6 +383,7 @@ (define (guix-substitute-binary . args)
"Implement the build daemon's substituter protocol."
(mkdir-p %narinfo-cache-directory)
(maybe-remove-expired-cached-narinfo)
(with-networking
(match args
(("--query")
(let ((cache (delay (open-cache %cache-url))))
@ -441,6 +455,6 @@ (define (guix-substitute-binary . args)
(restore-file input destination)
(every (compose zero? cdr waitpid) pids))))
(("--version")
(show-version-and-exit "guix substitute-binary"))))
(show-version-and-exit "guix substitute-binary")))))
;;; substitute-binary.scm ends here