From: typ22@foxmail.com
To: 57496@debbugs.gnu.org
Cc: julien@lepiller.eu, tiantian <typ22@foxmail.com>
Subject: [bug#57496] [PATCH v3 3/3] gnu: bootloader: Add a friendly error message of menu-entry.
Date: Sun, 4 Sep 2022 22:04:31 +0800 [thread overview]
Message-ID: <tencent_7C06FFA147888B51271E0803CBE2D620A005@qq.com> (raw)
In-Reply-To: <849b9ddea2a18dc4b2fd05450f0c90e3e5a05421.1662298270.git.typ22@foxmail.com>
From: tiantian <typ22@foxmail.com>
* gnu/bootloader.scm (report-menu-entry-error): New procedure.
(menu-entry->sexp): Modify the pattern and add `else' to call
`report-menu-entry-error'.
Co-Authored-By: Julien Lepiller <julien@lepiller.eu>
---
The error message like so:
guix system: error: invalid menu-entry: #<<menu-entry> label: "test" device: #<file-system-label "guix-root"> device-mount-point: #f linux: #f linux-arguments: () initrd: #f multiboot-kernel: #f multiboot-arguments: () multiboot-modules: () chain-loader: #f>
hint: Please chose only one of:
1. direct boot by specifying fields `linux', `linux-arguments' and `linux-modules',
2. multiboot by specifying fields `multiboot-kernel', `multiboot-arguments' and `multiboot-modules',
3. chain-loader by specifying field `chain-loader'.
The code of `report-menu-entry-error' is quoted from Julien Lepiller.
Thanks the help from Julien Lepiller.
gnu/bootloader.scm | 44 +++++++++++++++++++++++++++++++++++++++-----
1 file changed, 39 insertions(+), 5 deletions(-)
diff --git a/gnu/bootloader.scm b/gnu/bootloader.scm
index 9e8b545d10..d4fe460570 100644
--- a/gnu/bootloader.scm
+++ b/gnu/bootloader.scm
@@ -34,6 +34,8 @@ (define-module (gnu bootloader)
#:use-module (guix diagnostics)
#:use-module (guix i18n)
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-34)
+ #:use-module (srfi srfi-35)
#:use-module (ice-9 match)
#:export (menu-entry
menu-entry?
@@ -110,6 +112,23 @@ (define-record-type* <menu-entry>
(chain-loader menu-entry-chain-loader
(default #f))) ; string, path of efi file
+(define (report-menu-entry-error menu-entry)
+ (raise
+ (condition
+ (&message
+ (message
+ (format #f (G_ "invalid menu-entry: ~a") menu-entry)))
+ (&fix-hint
+ (hint
+ (G_ "Please chose only one of:
+@enumerate
+@item direct boot by specifying fields @code{linux},
+@code{linux-arguments} and @code{linux-modules},
+@item multiboot by specifying fields @code{multiboot-kernel},
+@code{multiboot-arguments} and @code{multiboot-modules},
+@item chain-loader by specifying field @code{chain-loader}.
+@end enumerate"))))))
+
(define (menu-entry->sexp entry)
"Return ENTRY serialized as an sexp."
(define (device->sexp device)
@@ -119,9 +138,21 @@ (define (menu-entry->sexp entry)
((? file-system-label? label)
`(label ,(file-system-label->string label)))
(_ device)))
+ (define (set-field? field)
+ "If the field is the default value, return #f."
+ (and field ; not default value #f
+ (not (null? field)))) ; not default value '()
(match entry
+ ;; Modify the pattern to achieve more strict matching and prevent
+ ;; wrong matching, which ensures the output of error information
+ ;; when menu-entry is wrong.
+
+ ;; The linux-arguments is optional and the test code for boot-parameters
+ ;; does not set it, so don't check it here.
(($ <menu-entry> label device mount-point
- (? identity linux) linux-arguments initrd
+ (? set-field? linux)
+ linux-arguments
+ (? set-field? initrd)
#f () () #f)
`(menu-entry (version 0)
(label ,label)
@@ -131,8 +162,10 @@ (define (menu-entry->sexp entry)
(linux-arguments ,linux-arguments)
(initrd ,initrd)))
(($ <menu-entry> label device mount-point #f () #f
- (? identity multiboot-kernel) multiboot-arguments
- multiboot-modules #f)
+ (? set-field? multiboot-kernel)
+ (? set-field? multiboot-arguments)
+ (? set-field? multiboot-modules)
+ #f)
`(menu-entry (version 0)
(label ,label)
(device ,(device->sexp device))
@@ -141,12 +174,13 @@ (define (menu-entry->sexp entry)
(multiboot-arguments ,multiboot-arguments)
(multiboot-modules ,multiboot-modules)))
(($ <menu-entry> label device mount-point #f () #f #f () ()
- (? identity chain-loader))
+ (? set-field? chain-loader))
`(menu-entry (version 0)
(label ,label)
(device ,(device->sexp device))
(device-mount-point ,mount-point)
- (chain-loader ,chain-loader)))))
+ (chain-loader ,chain-loader)))
+ (else (report-menu-entry-error entry))))
(define (sexp->menu-entry sexp)
"Turn SEXP, an sexp as returned by 'menu-entry->sexp', into a <menu-entry>
--
2.37.2
next prev parent reply other threads:[~2022-09-04 14:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <849b9ddea2a18dc4b2fd05450f0c90e3e5a05421.1662298270.git.typ22@foxmail.com>
2022-09-04 14:04 ` [bug#57496] [PATCH v3 2/3] gnu: bootloader: grub: Add support for chain-loader typ22
2022-09-04 14:04 ` typ22 [this message]
2022-09-04 15:37 ` [bug#57496] [PATCH v3 3/3] gnu: bootloader: Add a friendly error message of menu-entry Julien Lepiller
[not found] ` <7x7d2jt5z0.fsf@foxmail.com>
2022-09-04 16:15 ` tiantian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_7C06FFA147888B51271E0803CBE2D620A005@qq.com \
--to=typ22@foxmail.com \
--cc=57496@debbugs.gnu.org \
--cc=julien@lepiller.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).