[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
05/10: system: Improve 'read-boot-parameters' incompatibility diagnostic
From: |
guix-commits |
Subject: |
05/10: system: Improve 'read-boot-parameters' incompatibility diagnostic. |
Date: |
Wed, 16 Mar 2022 10:50:24 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit 47960b55268220ca1cb7d2fed41c53873181d816
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Wed Mar 16 15:03:01 2022 +0100
system: Improve 'read-boot-parameters' incompatibility diagnostic.
Previously, when reading an incompatible "parameters" file, 'guix
system' would print a warning and then crash with a wrong-type-arg
backtrace because code expects 'read-boot-parameters' to always return a
<boot-parameters> record.
* gnu/system.scm (read-boot-parameters): Upon incompatibility, raise an
error instead of returning #f. Also raise a '&fix-hint' condition.
* tests/boot-parameters.scm ("read, construction, mandatory fields"):
Define 'test-read-boot-parameters' as a macro; expect
'formatted-message?' exceptions rather than #f returns.
---
gnu/system.scm | 19 +++++++++++++++----
tests/boot-parameters.scm | 21 ++++++++++++++-------
2 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/gnu/system.scm b/gnu/system.scm
index dc980312ab..59b3dea93c 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -354,7 +354,7 @@ file system labels."
(define (read-boot-parameters port)
"Read boot parameters from PORT and return the corresponding
-<boot-parameters> object or #f if the format is unrecognized."
+<boot-parameters> object. Raise an error if the format is unrecognized."
(define device-sexp->device
(match-lambda
(('uuid (? symbol? type) (? bytevector? bv))
@@ -481,9 +481,20 @@ file system labels."
(_ ;the old format
"/")))))
(x ;unsupported format
- (warning (G_ "unrecognized boot parameters at '~a'~%")
- (port-filename port))
- #f)))
+ (raise
+ (make-compound-condition
+ (formatted-message
+ (G_ "unrecognized boot parameters at '~a'~%")
+ (port-filename port))
+ (condition
+ (&fix-hint (hint (format #f (G_ "This probably means that this version
+of Guix is older than the one that created @file{~a}. To address this, you
+need to update Guix:
+
+@example
+guix pull
+@end example")
+ (port-filename port))))))))))
(define (read-boot-parameters-file system)
"Read boot parameters from SYSTEM's (system or generation) \"parameters\"
diff --git a/tests/boot-parameters.scm b/tests/boot-parameters.scm
index d4b680df2e..8e48e1775e 100644
--- a/tests/boot-parameters.scm
+++ b/tests/boot-parameters.scm
@@ -28,9 +28,11 @@
#:use-module (gnu system)
#:use-module (gnu system file-systems)
#:use-module (gnu system uuid)
+ #:use-module ((guix diagnostics) #:select (formatted-message?))
#:use-module (guix gexp)
#:use-module (guix store)
#:use-module (guix tests)
+ #:use-module (srfi srfi-34)
#:use-module (srfi srfi-64)
#:use-module (rnrs bytevectors))
@@ -151,13 +153,18 @@
;; XXX: <warning: unrecognized boot parameters at '#f'>
(test-assert "read, construction, mandatory fields"
- (not (or (test-read-boot-parameters #:version #false)
- (test-read-boot-parameters #:version 'false)
- (test-read-boot-parameters #:version -1)
- (test-read-boot-parameters #:version "0")
- (test-read-boot-parameters #:root-device #false)
- (test-read-boot-parameters #:kernel #false)
- (test-read-boot-parameters #:label #false))))
+ (let-syntax ((test-read-boot-parameters
+ (syntax-rules ()
+ ((_ args ...)
+ (guard (c ((formatted-message? c) #f))
+ (test-read-boot-parameters args ...))))))
+ (not (or (test-read-boot-parameters #:version #false)
+ (test-read-boot-parameters #:version 'false)
+ (test-read-boot-parameters #:version -1)
+ (test-read-boot-parameters #:version "0")
+ (test-read-boot-parameters #:root-device #false)
+ (test-read-boot-parameters #:kernel #false)
+ (test-read-boot-parameters #:label #false)))))
(test-assert "read, construction, optional fields"
(and (test-read-boot-parameters #:bootloader-name #false)
- branch master updated (53d986215f -> 797e308047), guix-commits, 2022/03/16
- 01/10: gnu : nicotine+: Update to 3.2.1., guix-commits, 2022/03/16
- 04/10: gnu: cryfs: Update to 0.11.2., guix-commits, 2022/03/16
- 03/10: packages: 'modify-inputs' preserves outputs in 'replace' clauses., guix-commits, 2022/03/16
- 09/10: gnu: matterbridge: update to 1.24.0, guix-commits, 2022/03/16
- 05/10: system: Improve 'read-boot-parameters' incompatibility diagnostic.,
guix-commits <=
- 08/10: gnu: Add python-mathlibtools., guix-commits, 2022/03/16
- 06/10: gnu: python-gitlab: update to 3.2.0, guix-commits, 2022/03/16
- 07/10: gnu: dunst: Update to 1.8.1., guix-commits, 2022/03/16
- 02/10: tests: Exercise 'modify-inputs' with a 'replace' clause., guix-commits, 2022/03/16
- 10/10: gnu: Add tessen., guix-commits, 2022/03/16