diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2019-05-15 22:36:46 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2019-05-16 13:24:06 +0200 |
| commit | ce10e6053bb02e936b3a0862f3a3f86010b948d0 (patch) | |
| tree | a14e2532ae8d209963d3d179df6fc8dd57d1a4be | |
| parent | 6e633a510c53ac3130296bfd5ecf98506b499421 (diff) | |
guix system: Type-check the file or expression.
Previously, users would get a wrong-type-arg exception down the road
with an intimidating backtrace.
* guix/scripts/system.scm (process-action)[ensure-operating-system]: New
procedure.
Use it.
| -rw-r--r-- | guix/scripts/system.scm | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm index 8434d1ecaa9..60c1ca5c9a9 100644 --- a/guix/scripts/system.scm +++ b/guix/scripts/system.scm | |||
| @@ -1143,22 +1143,30 @@ Some ACTIONS support additional ARGS.\n")) | |||
| 1143 | ACTION must be one of the sub-commands that takes an operating system | 1143 | ACTION must be one of the sub-commands that takes an operating system |
| 1144 | declaration as an argument (a file name.) OPTS is the raw alist of options | 1144 | declaration as an argument (a file name.) OPTS is the raw alist of options |
| 1145 | resulting from command-line parsing." | 1145 | resulting from command-line parsing." |
| 1146 | (define (ensure-operating-system file-or-exp obj) | ||
| 1147 | (unless (operating-system? obj) | ||
| 1148 | (leave (G_ "'~a' does not return an operating system~%") | ||
| 1149 | file-or-exp)) | ||
| 1150 | obj) | ||
| 1151 | |||
| 1146 | (let* ((file (match args | 1152 | (let* ((file (match args |
| 1147 | (() #f) | 1153 | (() #f) |
| 1148 | ((x . _) x))) | 1154 | ((x . _) x))) |
| 1149 | (expr (assoc-ref opts 'expression)) | 1155 | (expr (assoc-ref opts 'expression)) |
| 1150 | (system (assoc-ref opts 'system)) | 1156 | (system (assoc-ref opts 'system)) |
| 1151 | (os (cond | 1157 | (os (ensure-operating-system |
| 1152 | ((and expr file) | 1158 | (or file expr) |
| 1153 | (leave | 1159 | (cond |
| 1154 | (G_ "both file and expression cannot be specified~%"))) | 1160 | ((and expr file) |
| 1155 | (expr | 1161 | (leave |
| 1156 | (read/eval expr)) | 1162 | (G_ "both file and expression cannot be specified~%"))) |
| 1157 | (file | 1163 | (expr |
| 1158 | (load* file %user-module | 1164 | (read/eval expr)) |
| 1159 | #:on-error (assoc-ref opts 'on-error))) | 1165 | (file |
| 1160 | (else | 1166 | (load* file %user-module |
| 1161 | (leave (G_ "no configuration specified~%"))))) | 1167 | #:on-error (assoc-ref opts 'on-error))) |
| 1168 | (else | ||
| 1169 | (leave (G_ "no configuration specified~%")))))) | ||
| 1162 | 1170 | ||
| 1163 | (dry? (assoc-ref opts 'dry-run?)) | 1171 | (dry? (assoc-ref opts 'dry-run?)) |
| 1164 | (bootloader? (assoc-ref opts 'install-bootloader?)) | 1172 | (bootloader? (assoc-ref opts 'install-bootloader?)) |
