From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 0EbrIGP6fWEF9AAAgWs5BA (envelope-from ) for ; Sun, 31 Oct 2021 03:07:31 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id aGifHGP6fWETdAAAB5/wlQ (envelope-from ) for ; Sun, 31 Oct 2021 02:07:31 +0000 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 8E46F9ED8 for ; Sun, 31 Oct 2021 03:07:29 +0100 (CET) Received: from localhost ([::1]:57554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mh0Fs-0002ZK-47 for larch@yhetil.org; Sat, 30 Oct 2021 22:07:28 -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 Content-Type: multipart/mixed; boundary="MP_/weRgIw/4gs/j4Y4tHo+voqE" 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1635646050; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: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=HpYAr90qvSc42Ep0l/YwYPZmD+YdXYF2by+RbYZrzdk=; b=AtjWm0ERcl5oFJjqpBeOaREp+yPJ7WIdQhRhcMix+ndKQhBD38v80ooLiuN6SgcKvOSZ4p sMsyKzxqNw5zdTyCXdJI9lCB+HvYl0OBbH7AD9bK4YXTAIpjQafXivL8TfAKb/jlgmBqcR U5bwzcX8AlDSuYJrIc1JPZWKlpWlGvwOHGK5pEQTQczBrjNjrV1zFRSK3RXzPxK/lbdnEB tLKr1YVFSXzz6gHpW8CBIAtRgbdz/CItNNX395RfckGzHBMGYxJ9bLtUgXhS52s+7qOJ/y MuRQuJVWUQKWx/TxOWJ+LPA31XP+lbDuUycaJC7IHmuGOgbuT7JHsp1mqIEtUg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1635646050; a=rsa-sha256; cv=none; b=aDqBbGEIvDoquOjPLRMVUlKEuO+DD6tUMhgmVjD8JRLy0cNXen7FREqZwXQsIiY7gt2hjG smASbk3DoW7Ysn5m3IsXlCBkU7BQhax+KwmorH2F+gDWTE/et8xugEmwYCcFIzvu/icoJi o0wNbal+q6nNvsuQqtpZMy0+zeMe16pdm9P66f953Ifg+xBQALQ/4yNLaU5BhOOiJqx8i/ oV8vQy8ea1XQh7nKfrkoR3mc8qlp1F+ET00U0unjwl/64GaB1iPj6md1C6UGVuiRYdhzJc fFHKtSiLr39CSXwu9l5m8CEa7l98nIvuf0zggNcs9eqygkmRu8A8qnumjYN4qA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=lepiller.eu header.s=dkim header.b=OPiqCVpu; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -1.32 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=lepiller.eu header.s=dkim header.b=OPiqCVpu; dmarc=fail reason="SPF not aligned (relaxed)" header.from=lepiller.eu (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 8E46F9ED8 X-Spam-Score: -1.32 X-Migadu-Scanner: scn0.migadu.com X-TUID: ictzT3Pdkrwb --MP_/weRgIw/4gs/j4Y4tHo+voqE Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline 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...) --MP_/weRgIw/4gs/j4Y4tHo+voqE Content-Type: text/x-patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=0001-guix-records-Improve-error-reporting.patch =46rom 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 =C2=A9 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020,= 2021 Ludovic Court=C3=A8s ;;; Copyright =C2=A9 2018 Mark H Weaver +;;; Copyright =C2=A9 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. Hopefu= lly ;; 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)) paren= t-properties) + '())))) + (syntax-case #'weird () + (() ;the empty list + (raise-exception + (condition + (&message (message (format #f (G_ "invalid field specifi= er: ~a") + #'weird))) + (&error-location (location location)) + (&fix-hint (hint (G_ "The format of a field is `(field v= alue)'")))))) + (((field ...) _ ...) ;a list whose first element i= s a list + (raise-exception + (condition + (&message (message (format #f (G_ "invalid field specifi= er: ~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 specifi= er"))) + (&error-location (location location)) + (&fix-hint (hint (format #f (G_ "~a values were associat= ed with \ +field `~a'. We got the following values:~%@lisp~%~{~a~%~}~%@end lisp~%Per= haps the additional values +were intended to be other field specifiers. This usually indicates missin= g 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 specifi= er: ~a") + #'weird))) + (&error-location (location location)) + (&fix-hint (hint (G_ "The format of a field is `(field v= alue)'")))))))))))) =20 (define (report-duplicate-field-specifier name ctor) "Report the first duplicate identifier among the bindings in CTOR." --=20 2.33.1 --MP_/weRgIw/4gs/j4Y4tHo+voqE--