import: hackage: Handle unknown packages gracefully.

* guix/import/hackage.scm (hackage-fetch): Add 'guard'.
This commit is contained in:
Federico Beffa 2017-02-09 17:05:41 +01:00
parent bc5844d149
commit a4824c60ef
No known key found for this signature in database
GPG Key ID: 58936E0E2F1B5A4C
1 changed files with 10 additions and 6 deletions

View File

@ -21,6 +21,7 @@
(define-module (guix import hackage) (define-module (guix import hackage)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:use-module (ice-9 regex) #:use-module (ice-9 regex)
#:use-module (srfi srfi-34)
#:use-module (srfi srfi-26) #:use-module (srfi srfi-26)
#:use-module (srfi srfi-11) #:use-module (srfi srfi-11)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
@ -115,12 +116,15 @@ version is returned."
"Return the Cabal file for the package NAME-VERSION, or #f on failure. If "Return the Cabal file for the package NAME-VERSION, or #f on failure. If
the version part is omitted from the package name, then return the latest the version part is omitted from the package name, then return the latest
version." version."
(let-values (((name version) (package-name->name+version name-version))) (guard (c ((and (http-get-error? c)
(let* ((url (hackage-cabal-url name version)) (= 404 (http-get-error-code c)))
(port (http-fetch url)) #f)) ;"expected" if package is unknown
(result (read-cabal (canonical-newline-port port)))) (let-values (((name version) (package-name->name+version name-version)))
(close-port port) (let* ((url (hackage-cabal-url name version))
result))) (port (http-fetch url))
(result (read-cabal (canonical-newline-port port))))
(close-port port)
result))))
(define string->license (define string->license
;; List of valid values from ;; List of valid values from