Skip to content
Snippets Groups Projects
Commit 6544aba5 authored by Federico Beffa's avatar Federico Beffa
Browse files

import: elpa: Improve error message reporting.

* guix/import/elpa.scm (filter-dependencies): Fix bug.
  (call-with-downloaded-file): Add optional parameter 'error-thunk'.
  (fetch-package-description): Use it.
parent 23bae7bb
No related branches found
No related tags found
No related merge requests found
...@@ -52,7 +52,7 @@ (define emacs-standard-library? ...@@ -52,7 +52,7 @@ (define emacs-standard-library?
(define (filter-dependencies names) (define (filter-dependencies names)
"Remove the package names included with Emacs from the list of "Remove the package names included with Emacs from the list of
NAMES (strings)." NAMES (strings)."
(filter emacs-standard-library? names)) (filter (compose not emacs-standard-library?) names))
(define (elpa-name->package-name name) (define (elpa-name->package-name name)
"Given the NAME of an Emacs package, return the corresponding Guix name." "Given the NAME of an Emacs package, return the corresponding Guix name."
...@@ -77,14 +77,17 @@ (define* (elpa-fetch-archive #:optional (repo 'gnu)) ...@@ -77,14 +77,17 @@ (define* (elpa-fetch-archive #:optional (repo 'gnu))
(call-with-downloaded-file url read) (call-with-downloaded-file url read)
(leave (_ "~A: currently not supported~%") repo)))) (leave (_ "~A: currently not supported~%") repo))))
(define (call-with-downloaded-file url proc) (define* (call-with-downloaded-file url proc #:optional (error-thunk #f))
"Fetch URL, store the content in a temporary file and call PROC with that "Fetch URL, store the content in a temporary file and call PROC with that
file. Returns the value returned by PROC." file. Returns the value returned by PROC. On error call ERROR-THUNK and
return its value or leave if it's false."
(call-with-temporary-output-file (call-with-temporary-output-file
(lambda (temp port) (lambda (temp port)
(or (and (url-fetch url temp) (or (and (url-fetch url temp)
(call-with-input-file temp proc)) (call-with-input-file temp proc))
(error "download failed" url))))) (if error-thunk
(error-thunk)
(leave (_ "~A: download failed~%") url))))))
(define (is-elpa-package? name elpa-pkg-spec) (define (is-elpa-package? name elpa-pkg-spec)
"Return true if the string NAME corresponds to the name of the package "Return true if the string NAME corresponds to the name of the package
...@@ -158,8 +161,9 @@ (define* (full-url repo name suffix #:optional (version #f)) ...@@ -158,8 +161,9 @@ (define* (full-url repo name suffix #:optional (version #f))
(define (fetch-package-description kind name repo) (define (fetch-package-description kind name repo)
"Fetch the description of package NAME of type KIND from REPO." "Fetch the description of package NAME of type KIND from REPO."
(let ((url (full-url repo name "-readme.txt"))) (let ((url (full-url repo name "-readme.txt"))
(call-with-downloaded-file url read-string))) (error-thunk (lambda () "No description available.")))
(call-with-downloaded-file url read-string error-thunk)))
(define* (fetch-elpa-package name #:optional (repo 'gnu)) (define* (fetch-elpa-package name #:optional (repo 'gnu))
"Fetch package NAME from REPO." "Fetch package NAME from REPO."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment