guix build: Gracefully handle type errors in -e and -f.

* guix/scripts/build.scm (options->things-to-build)[validate-type]: New
procedure.
[ensure-list]: Use it.
This commit is contained in:
Ludovic Courtès 2015-12-13 21:13:16 +01:00
parent ee2a7e3fd2
commit 20464dde13
1 changed files with 10 additions and 4 deletions

View File

@ -404,10 +404,16 @@ must be one of 'package', 'all', or 'transitive'~%")
(define (options->things-to-build opts) (define (options->things-to-build opts)
"Read the arguments from OPTS and return a list of high-level objects to "Read the arguments from OPTS and return a list of high-level objects to
build---packages, gexps, derivations, and so on." build---packages, gexps, derivations, and so on."
(define ensure-list (define (validate-type x)
(match-lambda (unless (or (package? x) (derivation? x) (gexp? x) (procedure? x))
(leave (_ "~s: not something we can build~%") x)))
(define (ensure-list x)
(let ((lst (match x
((x ...) x) ((x ...) x)
(x (list x)))) (x (list x)))))
(for-each validate-type lst)
lst))
(append-map (match-lambda (append-map (match-lambda
(('argument . (? string? spec)) (('argument . (? string? spec))