From patchwork Sun Oct 31 02:06:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Julien Lepiller X-Patchwork-Id: 34185 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 E2CE427BBE3; Sun, 31 Oct 2021 02:07:28 +0000 (GMT) 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_H2,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 52D7727BBE1 for ; Sun, 31 Oct 2021 02:07:28 +0000 (GMT) Received: from localhost ([::1]:57554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mh0Fr-0002ZK-F7 for patchwork@mira.cbaines.net; Sat, 30 Oct 2021 22:07:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mh0FS-0002Z8-Kl for guix-patches@gnu.org; Sat, 30 Oct 2021 22:07:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:47165) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mh0FS-0008U0-CD for guix-patches@gnu.org; Sat, 30 Oct 2021 22:07:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mh0FS-0001QT-5V for guix-patches@gnu.org; Sat, 30 Oct 2021 22:07:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49671] [PATCH] guix: records: Improve error reporting. References: <20210721014047.3878a0c7@tachikoma.lepiller.eu> In-Reply-To: <20210721014047.3878a0c7@tachikoma.lepiller.eu> Resent-From: Julien Lepiller Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 31 Oct 2021 02:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49671 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49671@debbugs.gnu.org Received: via spool by 49671-submit@debbugs.gnu.org id=B49671.16356460125463 (code B ref 49671); Sun, 31 Oct 2021 02:07:02 +0000 Received: (at 49671) by debbugs.gnu.org; 31 Oct 2021 02:06:52 +0000 Received: from localhost ([127.0.0.1]:58711 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mh0FH-0001Q1-JE for submit@debbugs.gnu.org; Sat, 30 Oct 2021 22:06:52 -0400 Received: from lepiller.eu ([89.234.186.109]:37270) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mh0FC-0001Pl-Jh for 49671@debbugs.gnu.org; Sat, 30 Oct 2021 22:06:49 -0400 Received: from lepiller.eu (localhost [127.0.0.1]) by lepiller.eu (OpenSMTPD) with ESMTP id b31e2f7e for <49671@debbugs.gnu.org>; Sun, 31 Oct 2021 02:06:42 +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=aUq HEZ0OtEw2e9Iz6TavwSjSwxhAkChHvn1GtsYsQeI=; b=OPiqCVpue3rwqc8AEYU 4G/wszXG3psKLHYG0m6ho3WLPX/vaT+5tKCP6ddT53791iTLYC0cjRuQvGLAVB4g AqRa0sJgSFdARhoziQEoeZGCbzCiFiE43B68ME3u3NYbDSiL7Hw4c+b1Y9+jdeor OHh/F/fhXAwFhCJpZCY2Pdjq8CghB1LoLwcdXibPV2iN+2iHp5wELny5mjOUHzpo NODM6rjgTD9tfO6ZwDw7z7fc0/UnfboCJn3S8ekcK00vbOSNu5Vg8kLTqhKPdvIG n2/cUWFDv0juY+HLWY+KbwF6MS3f/IJO/cDnBGKTRVzJzdImZn2zNbfeRaNN02gS UAw== Received: by lepiller.eu (OpenSMTPD) with ESMTPSA id 107fcaa5 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for <49671@debbugs.gnu.org>; Sun, 31 Oct 2021 02:06:42 +0000 (UTC) Date: Sun, 31 Oct 2021 03:06:35 +0100 From: Julien Lepiller Message-ID: <20211031030635.520a3c6c@tachikoma.lepiller.eu> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.24; x86_64-pc-linux-gnu) 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 Hi Guix! Here is a new patch that attempts to better catch various causes of syntax errors in records. I think I fixed all the concerns Ludo had, and I draw some inspiration from https://issues.guix.gnu.org/50914 for using conditions. Here are examples of what you get: (operating-system ()) test.scm:1:0: error: invalid field specifier: () hint: The format of a field is `(field value)' (operating-system ((services %base-services))) test.scm:1:0: error: invalid field specifier: (services %base-services) is not a valid field name (operating-system (services)) test.scm:1:0: error: missing value in field specifier hint: The field is missing a value: `(services )'. (operating-system (services (service tor-service-type) %base-services)) test.scm:1:0: error: multiple values in field specifier hint: 2 values were associated with field `services'. We got the following values: (service tor-service-type) %base-services Perhaps the additional values were intended to be other field specifiers. This usually indicates missing or misplaced parenthesis. (operating-system services %base-services) test.scm:1:0: error: invalid field specifier: # hint: The format of a field is `(field value)' (not sure why the last one is wrapped in syntax...) From 9e08a887a08da3f0cc132d148b748eb2ce7db135 Mon Sep 17 00:00:00 2001 Message-Id: <9e08a887a08da3f0cc132d148b748eb2ce7db135.1635645523.git.julien@lepiller.eu> From: Julien Lepiller Date: Sun, 31 Oct 2021 02:58:14 +0100 Subject: [PATCH] guix: records: Improve error reporting. * guix/records.scm (report-invalid-field-specifier): Handle various invalidity causes separately. --- guix/records.scm | 56 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/guix/records.scm b/guix/records.scm index ed94c83dac..9baa2c2f1d 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, 2021 Ludovic Courtès ;;; Copyright © 2018 Mark H Weaver +;;; Copyright © 2021 Julien Lepiller ;;; ;;; This file is part of GNU Guix. ;;; @@ -21,9 +22,13 @@ (define-module (guix records) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-35) + #:use-module (ice-9 format) #:use-module (ice-9 match) #:use-module (ice-9 regex) #:use-module (ice-9 rdelim) + #:use-module (guix diagnostics) + #:use-module (guix ui) #:autoload (system base target) (target-most-positive-fixnum) #:export (define-record-type* this-record @@ -83,10 +88,53 @@ (define-syntax record-error ;; 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 - (list parent-form #'weird) - (list #'weird))))))) + (let* ((weird-properties (source-properties #'weird)) + (parent-properties (and parent-form (syntax-source parent-form))) + (location (source-properties->location + (or (and (not (null? weird-properties)) weird-properties) + (and (not (null? parent-properties)) parent-properties) + '())))) + (syntax-case #'weird () + (() ;the empty list + (raise-exception + (condition + (&message (message (format #f (G_ "invalid field specifier: ~a") + #'weird))) + (&error-location (location location)) + (&fix-hint (hint (G_ "The format of a field is `(field value)'")))))) + (((field ...) _ ...) ;a list whose first element is a list + (raise-exception + (condition + (&message (message (format #f (G_ "invalid field specifier: ~a \ +is not a valid field name") + (map syntax->datum #'(field ...))))) + (&error-location (location location))))) + ((field) ;a list with one element + (raise-exception + (condition + (&message (message (G_ "missing value in field specifier"))) + (&error-location (location location)) + (&fix-hint (hint (format #f (G_ "The field is missing a value: `(~a )'.") + (syntax->datum #'field))))))) + ((field value ...) ;any other list + (raise-exception + (condition + (&message (message (G_ "multiple values in field specifier"))) + (&error-location (location location)) + (&fix-hint (hint (format #f (G_ "~a values were associated with \ +field `~a'. We got the following values:~%@lisp~%~{~a~%~}~%@end lisp~%Perhaps the additional values +were intended to be other field specifiers. This usually indicates missing or \ +misplaced parenthesis.") + (length #'(value ...)) + (syntax->datum #'field) + (map syntax->datum #'(value ...)))))))) + (field ;not a list + (raise-exception + (condition + (&message (message (format #f (G_ "invalid field specifier: ~a") + #'weird))) + (&error-location (location location)) + (&fix-hint (hint (G_ "The format of a field is `(field value)'")))))))))))) (define (report-duplicate-field-specifier name ctor) "Report the first duplicate identifier among the bindings in CTOR." -- 2.33.1