From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id ENGgLbOyFGOmDQEAbAwnHQ (envelope-from ) for ; Sun, 04 Sep 2022 16:14:11 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 8HGOLbOyFGP/dgAA9RJhRA (envelope-from ) for ; Sun, 04 Sep 2022 16:14:11 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 731213E7C5 for ; Sun, 4 Sep 2022 16:14:11 +0200 (CEST) Received: from localhost ([::1]:37650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oUqO2-0006O4-NR for larch@yhetil.org; Sun, 04 Sep 2022 10:14:10 -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 2022 22:10:46 +0800 X-QQ-mid: xmsmtpt1662300662t6jskf6y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-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 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1662300851; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=+hv/+969LXAcQQ5jo+zvptqiwt6JiG5YCxy5zn3y0LY=; b=VRZAtQ44Oua6whTEfjdomAIzNRTgWAIilNt+kYqWQqKrUmfTpjOlicBqyzELvjVZjaAGz7 syc1UYISQ/AZcS9eLASn/cfWsYrYMAd612BVDD3l4YZPEWQfgSOpVr8T3DPZPk5+TSQVKW lgpaUlBric2CQBqvPDlyxA1/VcBKwofy/S7IDPbfhxTIIAXhUhWmPZTdmdHzJAPGutJrZa kaXLMzmzOmLpYsgGETHT1Kiw48Wp8QNZQ/AMxwTm/btYRiHSGGFpk8sldObHjZWhZef7yD 8lmQyv6t2tUTw03s6VZQhcKji/geT3JEtgAkOxPjIOuVfCfQ9PL0s2INW795WQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1662300851; a=rsa-sha256; cv=none; b=gM5h8mjo1mcjGqBaHRwytx2mxZ8rLcD6g4cO/Q/2+qml+bRtbVNiVWJ5dB6xxY6nBJZocq gXsI0S1O/d+/hpIS64Jtu+R9KaR/n/36dQwK6+QPRYk67AcyUqfbfDuJRS3/7xJ0ELWHuG NxTOy7rojMhoAmT0+UPF94APBnNNwHbNXFW3tjJaJCPBmvmPS5pb2UKPsch3/Yi97LexQX v+DpD/7rxeS20ptVNdYeboimFkINMGHwfbDGdPiON6X+kry5GpJhosr2faR3i7eE026fHg TpjxHl/43CGgStUlulVtYu509zFBgi8BZSGEAYb9GuwdmMmHDgq0EvidDrHyJg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=foxmail.com header.s=s201512 header.b="wEZYSlo/"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=foxmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 5.32 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=foxmail.com header.s=s201512 header.b="wEZYSlo/"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=foxmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 731213E7C5 X-Spam-Score: 5.32 X-Migadu-Scanner: scn0.migadu.com X-TUID: Oa38XWeS6Abz 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 -- 2.37.2