From patchwork Sun Sep 4 14:04:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tiantian X-Patchwork-Id: 42206 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id EC99C27BBEA; Sun, 4 Sep 2022 15:14:13 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 566AD27BBE9 for ; Sun, 4 Sep 2022 15:14:13 +0100 (BST) Received: from localhost ([::1]:37650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oUqO4-0006O4-Hp for patchwork@mira.cbaines.net; Sun, 04 Sep 2022 10:14:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUqNu-0006Nv-Pa for guix-patches@gnu.org; Sun, 04 Sep 2022 10:14:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:56660) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oUqNu-0003Fc-Fb for guix-patches@gnu.org; Sun, 04 Sep 2022 10:14:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oUqNu-0002BF-3S for guix-patches@gnu.org; Sun, 04 Sep 2022 10:14:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#57496] [PATCH v3 3/3] gnu: bootloader: Add a friendly error message of menu-entry. Resent-From: typ22@foxmail.com Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 04 Sep 2022 14:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57496 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 57496@debbugs.gnu.org Cc: julien@lepiller.eu, tiantian Received: via spool by 57496-submit@debbugs.gnu.org id=B57496.16623008068331 (code B ref 57496); Sun, 04 Sep 2022 14:14:02 +0000 Received: (at 57496) by debbugs.gnu.org; 4 Sep 2022 14:13:26 +0000 Received: from localhost ([127.0.0.1]:45359 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUqNJ-0002AJ-H8 for submit@debbugs.gnu.org; Sun, 04 Sep 2022 10:13:26 -0400 Received: from out162-62-57-64.mail.qq.com ([162.62.57.64]:36331) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUqNF-0002A0-Vm for 57496@debbugs.gnu.org; Sun, 04 Sep 2022 10:13:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1662300791; bh=+hv/+969LXAcQQ5jo+zvptqiwt6JiG5YCxy5zn3y0LY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wEZYSlo/Y60x1hmGpfHOvscMbzv71UrqqlPTdU550EUFSTug5XTtEaMAP8uNiA/W+ t21xclcp3OUifKTXaylNQMVukWjXTubdMToL+YSLe53YT7JEl67j+rk5nLhyzDRcKT ldMtEL9NBxV1QGM+BOw9WlNTETgY8X+PEgW9na6g= Received: from localhost.localdomain ([240e:398:28a4:3121:5ae1:85dd:ab7b:103f]) by newxmesmtplogicsvrsza7.qq.com (NewEsmtp) with SMTP id 2AE98672; Sun, 04 Sep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typ22@foxmail.com Date: Sun, 4 Sep 2022 22:04:31 +0800 X-OQ-MSGID: <35555a74cdf7ec6038b2f37aa1831edcace04c21.1662298270.git.typ22@foxmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <849b9ddea2a18dc4b2fd05450f0c90e3e5a05421.1662298270.git.typ22@foxmail.com> References: <849b9ddea2a18dc4b2fd05450f0c90e3e5a05421.1662298270.git.typ22@foxmail.com> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches From: tiantian * 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 --- The error message like so: guix system: error: invalid menu-entry: #< label: "test" device: # 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* (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. (($ 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))) (($ 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))) (($ 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