From patchwork Tue Jul 20 23:40:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Julien Lepiller X-Patchwork-Id: 31533 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 E7F6327BC78; Wed, 21 Jul 2021 00:53:36 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 71ADE27BC6B for ; Wed, 21 Jul 2021 00:53:36 +0100 (BST) Received: from localhost ([::1]:47882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5zYN-0007Ud-F5 for patchwork@mira.cbaines.net; Tue, 20 Jul 2021 19:53:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5zNC-0008Df-RG for guix-patches@gnu.org; Tue, 20 Jul 2021 19:42:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:52369) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m5zNC-0006a9-Ia for guix-patches@gnu.org; Tue, 20 Jul 2021 19:42:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m5zNC-0006cn-Dj for guix-patches@gnu.org; Tue, 20 Jul 2021 19:42:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49671] [PATCH] guix: records: Improve error reporting. Resent-From: Julien Lepiller Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 20 Jul 2021 23:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 49671 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49671@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.162682447525407 (code B ref -1); Tue, 20 Jul 2021 23:42:02 +0000 Received: (at submit) by debbugs.gnu.org; 20 Jul 2021 23:41:15 +0000 Received: from localhost ([127.0.0.1]:35682 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m5zMQ-0006bi-JL for submit@debbugs.gnu.org; Tue, 20 Jul 2021 19:41:14 -0400 Received: from lists.gnu.org ([209.51.188.17]:52842) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m5zMO-0006bb-OL for submit@debbugs.gnu.org; Tue, 20 Jul 2021 19:41:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5zMN-0006g2-At for guix-patches@gnu.org; Tue, 20 Jul 2021 19:41:11 -0400 Received: from lepiller.eu ([2a00:5884:8208::1]:41982) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5zMJ-0005sI-Dg for guix-patches@gnu.org; Tue, 20 Jul 2021 19:41:10 -0400 Received: from lepiller.eu (localhost [127.0.0.1]) by lepiller.eu (OpenSMTPD) with ESMTP id 3e99d9b3 for ; Tue, 20 Jul 2021 23:41:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=lepiller.eu; h=date:from :to:subject:message-id:mime-version:content-type; s=dkim; bh=Jzv L5p/FEwCJ8aKOL34W4e/+7g+irLG2mi7B79llZOo=; b=R4CRQysHkDD5S/eZfR2 rYy2QmQfl8P5+3YLV+ZDkniK4wcw7vEEt0pt3JdK2m8or/KVvPFueX+R8E1tznfe Y9e66xsIS3Mr0th51irTcVEuYWB9fllC/810K36rGPquuATaVnp8+ko8VboStIgK CQtHdawfzaCwJass2+dNVEc/vRHGqHd8lPJzc3DGTZSGxvJ1KGCoMg6fKGtM6d0e Jjv+UkHZLxOQHllGmOdyTPQborpi/F6jn61Uzwrb+ZlrG4WD4IEnHoWr8qveyAuU UTYrKQAf/s7cWBc1M5UhM3IQieoxnzAN+VyUPMrk/cJFJsOMj6MJjuisF7Q1WDiD fHQ== Received: by lepiller.eu (OpenSMTPD) with ESMTPSA id acbfdb09 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for ; Tue, 20 Jul 2021 23:41:00 +0000 (UTC) Date: Wed, 21 Jul 2021 01:40:47 +0200 From: Julien Lepiller Message-ID: <20210721014047.3878a0c7@tachikoma.lepiller.eu> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:5884:8208::1; envelope-from=julien@lepiller.eu; helo=lepiller.eu X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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 Hi Guix! This patch improves error reporting a bit when making mistakes in guix records. This is motivated by a user getting "invalid field specifier" for their whole services field in their os record. With this patches, they would have seen: multiple values in field specifier. Got 2 values associated with key services. Values are: (append (list (service ...) ...)) (modify-services %desktop-services ...) Which would have hinted them at fixing the parenthesis. Or at least, it would have saved us some time trying to count them :) Here are the cases that are handled and the associated message: (operating-system services) guix system: error: services: invalid field specifier. The format of a field is `(services value)' (operating-system (services)) test.scm:2:2: error: (services): Value missing in field specifier. The format of a field is `(services value)'. (operating-system (services 1 2 3)) test.scm:2:2: error: (services 1 2 3): multiple values in field specifier. Got 3 values associated with key services. Values are: 1 2 3 (operating-system ()) guix system: error: (): invalid field specifier. The format of a field is `(field value)' (operating-system ((services %desktop-services))) test.scm:2:2: error: ((services %desktop-services)): invalid field specifier. (services %desktop-services) is not a valid field name. Of course, we can improve these error messages, and internationalize them. WDYT? From 4cde5555682ca6a3c78cb274cc308087e51ea0e9 Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Wed, 21 Jul 2021 01:30:04 +0200 Subject: [PATCH] guix: records: Improve error reporting. * guix/records.scm (report-invalid-field-specifier): Handle various invalidity causes separately. --- guix/records.scm | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/guix/records.scm b/guix/records.scm index 3d54a51956..3c3dd478a5 100644 --- a/guix/records.scm +++ b/guix/records.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès ;;; Copyright © 2018 Mark H Weaver +;;; Copyright © 2021 Julien Lepiller ;;; ;;; This file is part of GNU Guix. ;;; @@ -83,10 +84,40 @@ error-reporting purposes." ;; WEIRD may be an identifier, thus lacking source location info, and ;; BINDINGS is a list, also lacking source location info. Hopefully ;; PARENT-FORM provides source location info. - (apply syntax-violation name "invalid field specifier" - (if parent-form + (syntax-case #'weird () + (() ;the empty list + (apply syntax-violation name + "invalid field specifier. The format of a field is `(field value)'" (list parent-form #'weird) - (list #'weird))))))) + (list #'weird))) + (((field ...) _ ...) ;a list whose first element is a list + (apply syntax-violation name + (format #f "invalid field specifier. ~a is not a valid field name." + (map syntax->datum #'(field ...))) + (list parent-form #'weird) + (list #'weird))) + ((field) ;a list with one element + (apply syntax-violation name + (format #f "Value missing in field specifier. The format of \ +a field is `(~a value)'." + (syntax->datum #'field)) + (list parent-form #'weird) + (list #'weird))) + ((field value ...) ;any other list + (apply syntax-violation name + (format #f "multiple values in field specifier. Got ~a values \ +associated with key ~a. Values are:~%~{~a~%~}" + (length #'(value ...)) (syntax->datum #'field) + (map syntax->datum #'(value ...))) + (list parent-form #'weird) + (list #'weird))) + (field ;not a list + (apply syntax-violation name + (format #f "invalid field specifier. The format of a field \ +is `(~a value)'" + (syntax->datum #'field)) + (list parent-form #'weird) + (list #'weird)))))))) (define (report-duplicate-field-specifier name ctor) "Report the first duplicate identifier among the bindings in CTOR." -- 2.32.0