From unknown Sat Jun 14 03:51:38 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#49671 <49671@debbugs.gnu.org> To: bug#49671 <49671@debbugs.gnu.org> Subject: Status: [PATCH] guix: records: Improve error reporting. Reply-To: bug#49671 <49671@debbugs.gnu.org> Date: Sat, 14 Jun 2025 10:51:38 +0000 retitle 49671 [PATCH] guix: records: Improve error reporting. reassign 49671 guix-patches submitter 49671 Julien Lepiller severity 49671 normal tag 49671 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 20 19:41:15 2021 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 To: guix-patches@gnu.org Subject: [PATCH] guix: records: Improve error reporting. 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 Content-Type: multipart/mixed; boundary="MP_/e6eTRR3_p7yxMS_Ql97axbF" 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-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --MP_/e6eTRR3_p7yxMS_Ql97axbF Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline 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? --MP_/e6eTRR3_p7yxMS_Ql97axbF Content-Type: text/x-patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=0001-guix-records-Improve-error-reporting.patch =46rom 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 =C2=A9 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 = Ludovic Court=C3=A8s ;;; Copyright =C2=A9 2018 Mark H Weaver +;;; Copyright =C2=A9 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. Hopefu= lly ;; 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 `(f= ield 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 forma= t 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 f= ield \ +is `(~a value)'" + (syntax->datum #'field)) + (list parent-form #'weird) + (list #'weird)))))))) =20 (define (report-duplicate-field-specifier name ctor) "Report the first duplicate identifier among the bindings in CTOR." --=20 2.32.0 --MP_/e6eTRR3_p7yxMS_Ql97axbF-- From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 21 15:21:31 2021 Received: (at 49671) by debbugs.gnu.org; 21 Jul 2021 19:21:31 +0000 Received: from localhost ([127.0.0.1]:38632 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m6Hmd-0008TB-Gl for submit@debbugs.gnu.org; Wed, 21 Jul 2021 15:21:31 -0400 Received: from out0.migadu.com ([94.23.1.103]:61474) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m6Hma-0008T2-9h for 49671@debbugs.gnu.org; Wed, 21 Jul 2021 15:21:29 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mgsn.dev; s=key1; t=1626895287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gdXPv+8jNSvtGV4MuiX4qeWrT3MmuIX8Wddxkkk6gcM=; b=MAGZ8S+PICWvzxfTbxhqvaNmYxNLpiyEmvfUCqeyVosPUUh6EUZOCv7GQNYWVi+aJCcYst 7NaXQgEh2dqShRHu7DiSy09Q+dIR+mYp0fe/aXcW/rVvud/U4rfM1xWzuqbzquPEHcJpj0 y/9wfkq/rvEwa3GIp52zUHPyF+Gb8So= From: Sarah Morgensen To: Julien Lepiller Subject: Re: bug#49671: [PATCH] guix: records: Improve error reporting. References: <20210721014047.3878a0c7@tachikoma.lepiller.eu> Date: Wed, 21 Jul 2021 12:21:23 -0700 In-Reply-To: <20210721014047.3878a0c7@tachikoma.lepiller.eu> (Julien Lepiller's message of "Wed, 21 Jul 2021 01:40:47 +0200") Message-ID: <86zgufscb0.fsf@mgsn.dev> MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: iskarian@mgsn.dev X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 49671 Cc: 49671@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Hi Julien, Julien Lepiller writes: > 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: After applying your patch, I get: --8<---------------cut here---------------start------------->8--- guix/records.scm:108:19: warning: "multiple values in field specifier. Got ~a values associated with key ~a. Values are:~%~{~a~%~}": unsupported format option ~{, use (ice-9 format) instead --8<---------------cut here---------------end--------------->8--- After adding `(ice-9 format)` to imports it works as expected. I see this also applies to package records! This will be great for those starting to package in Guix. > > 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: ^ Wrap in `'? > 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. ^ Should this also be wrapped in `'? Why do some of these messages lose their context and come from `guix system` instead? > > Of course, we can improve these error messages, and internationalize > them. > > WDYT? [...] > - (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))) Why the extra `(list #'weird')`? AFAICT right now this is providing `(list parent-form #:'weird)` as the parent form. And since parent-form is optional, shouldn't this be --8<---------------cut here---------------start------------->8--- (apply syntax-violation name "invalid field specifier. The format of a field is `(field value)'" (if parent-form (list parent-form #:'weird) (list weird))) --8<---------------cut here---------------end--------------->8--- (and similar for the others)? -- Sarah From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 04 11:20:01 2021 Received: (at 49671) by debbugs.gnu.org; 4 Aug 2021 15:20:01 +0000 Received: from localhost ([127.0.0.1]:44942 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mBIga-0008J3-Nu for submit@debbugs.gnu.org; Wed, 04 Aug 2021 11:20:00 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33762) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mBIgY-0008Ir-Ou for 49671@debbugs.gnu.org; Wed, 04 Aug 2021 11:19:59 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:34204) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mBIgQ-0004C3-P3; Wed, 04 Aug 2021 11:19:50 -0400 Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=43036 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mBIgP-0001un-Is; Wed, 04 Aug 2021 11:19:50 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Julien Lepiller Subject: Re: bug#49671: [PATCH] guix: records: Improve error reporting. References: <20210721014047.3878a0c7@tachikoma.lepiller.eu> Date: Wed, 04 Aug 2021 17:19:47 +0200 In-Reply-To: <20210721014047.3878a0c7@tachikoma.lepiller.eu> (Julien Lepiller's message of "Wed, 21 Jul 2021 01:40:47 +0200") Message-ID: <87bl6dp78s.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 49671 Cc: 49671@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hello! Julien Lepiller skribis: > 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. I like the idea! I would prefer for error messages to be plain errors, without hints, so: test.scm:2:2: error: (services 1 2 3): multiple values in field specifier (Not a sentence, no period.) But I=E2=80=99d also like to have hints, and ideally all hints should be reported consistently, via =E2=80=98&fix-hint=E2=80=99 or similar. Thankfully, we can do that via (guix diagnostics) + SRFI-35/34: (raise (condition (&syntax (form 'x) (subform 'y)) (&fix-hint (hint "Consider fixing this.")))) =E2=80=98call-with-error-handling=E2=80=99 in (guix ui) might need to be ad= justed. The only downside is that (guix records) would now depend on another Guix modules, which I tried to avoid so far so it could be more easily reused elsewhere. But that=E2=80=99s the price to pay to get consistent er= ror reports, and I think it=E2=80=99s okay. Note that =E2=80=98tests/guix-system.sh=E2=80=99 and a couple of other file= s test exact error reports, so we=E2=80=99ll have to make sure it still works and possib= ly augment the tests. WDYT? Thanks, Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 04 10:26:45 2021 Received: (at 49671) by debbugs.gnu.org; 4 Oct 2021 14:26:45 +0000 Received: from localhost ([127.0.0.1]:38050 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mXOvV-0005ZW-Ft for submit@debbugs.gnu.org; Mon, 04 Oct 2021 10:26:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45448) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mXOvT-0005ZD-As; Mon, 04 Oct 2021 10:26:43 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:55938) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mXOvM-0008E6-MI; Mon, 04 Oct 2021 10:26:37 -0400 Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=60564 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXOvM-0003s2-Ao; Mon, 04 Oct 2021 10:26:36 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Maxime Devos Subject: Re: bug#50914: [PATCH] records: Raise a &fix-hint if a field has multiple values. References: <20210930093229.4730-1-maximedevos@telenet.be> Date: Mon, 04 Oct 2021 16:26:33 +0200 In-Reply-To: <20210930093229.4730-1-maximedevos@telenet.be> (Maxime Devos's message of "Thu, 30 Sep 2021 11:32:29 +0200") Message-ID: <87r1d0ooh2.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 49671 Cc: 49671@debbugs.gnu.org, 50914@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi, Maxime Devos skribis: > * guix/records.scm (report-invalid-field-specifier): If > 'weird' is something like (field (record ...) extra ...), hint that 'ex= tra > ...' should probably be moved inside (record ...). Please see also . > + (condition > + (&origin (origin name)) > + (&message (message > + (format #f "field =E2=80=98~a=E2=80=99 should= only have one \ > +value, but an extra value =E2=80=98~a=E2=80=99 was passed as well. Perh= aps this extra \ > +value was supposed to be a field specifier, and needs to be moved inside= \ > +the record =E2=80=98~a=E2=80=99?" We=E2=80=99ll need i18n here and straight quotes. > + (&syntax (form (car forms)) > + (subform (and (not (null? (cdr forms))) > + (cadr forms)))) No cadrcdr please. :-) > + (&fix-hint (hint (object->string > + (syntax->datum > + #'(field > + (record-name fields ... extra-value > + extra-value* ...)))))= )))) The =E2=80=98hint=E2=80=99 field must be a string, typically the message yo= u had above; see other examples in the code. TIA! Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 30 22:06:52 2021 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 To: 49671@debbugs.gnu.org Subject: [PATCH] guix: records: Improve error reporting. 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-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 49671 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --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-- From debbugs-submit-bounces@debbugs.gnu.org Sun Nov 21 21:40:35 2021 Received: (at 49671) by debbugs.gnu.org; 22 Nov 2021 02:40:35 +0000 Received: from localhost ([127.0.0.1]:46462 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mozFy-0000va-LP for submit@debbugs.gnu.org; Sun, 21 Nov 2021 21:40:35 -0500 Received: from lepiller.eu ([89.234.186.109]:40274) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mozFv-0000vQ-PL for 49671@debbugs.gnu.org; Sun, 21 Nov 2021 21:40:33 -0500 Received: from lepiller.eu (localhost [127.0.0.1]) by lepiller.eu (OpenSMTPD) with ESMTP id 0fb7133e for <49671@debbugs.gnu.org>; Mon, 22 Nov 2021 02:40:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=lepiller.eu; h=date:from :to:subject:message-id:in-reply-to:references:mime-version :content-type; s=dkim; bh=iGD6lU7sHEq64YvvtH8vPHWZeUwfOdHKzjJUAW Ww3aw=; b=Ba28/Xa2ZhHZ0BeOM6F0bIV55BrRVZRct9N8yrQVxdRHHgUuUgkCJZ gbHNIP+0bXWLXUel/TXoIK6lSbctWVKh++32+cezu1RYhqRXjov+8VnNu4xfI2Eq cwc6yx2yuSiS7iJNr3iAA5I5D/mdE4wc9ffQegt1gtUX0VkCd3EPDkkx/3e3y2r5 qwMJj3aOvhUgVSlS2F6yGjMETOmBPC/VZhnUliPcb8BotIlqJ/NnLmMJLw5IHP+1 2qQgA7T8iXF40ozQNCJEmiprAwUX813uYa5Ylbc/iSl8ToAQ9gI630x4XXObNx3O S4HweRrIFKoXcplW0IZzYZP/AzuqGFIw== Received: by lepiller.eu (OpenSMTPD) with ESMTPSA id 61c83d1c (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for <49671@debbugs.gnu.org>; Mon, 22 Nov 2021 02:40:29 +0000 (UTC) Date: Mon, 22 Nov 2021 03:40:22 +0100 From: Julien Lepiller To: 49671@debbugs.gnu.org Subject: Re: [bug#49671] [PATCH v3] guix: records: Improve error reporting. Message-ID: <20211122034022.152daf55@tachikoma.lepiller.eu> In-Reply-To: <20211031030635.520a3c6c@tachikoma.lepiller.eu> References: <20210721014047.3878a0c7@tachikoma.lepiller.eu> <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_/O=5syjF3.pIA+c2Heao74c0" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 49671 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --MP_/O=5syjF3.pIA+c2Heao74c0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Here is another improvement compared to v2. This time there are two patches: the first adds support for &syntax in (guix ui), and will print something like in form: where "in form" is in green. The second patch is very similar to v2, but will now also raise a &syntax condition, so it can be pretty-printed. The previous issue where I printed # is fixed, I simply forgot a syntax->datum. WDYT? --MP_/O=5syjF3.pIA+c2Heao74c0 Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-guix-ui-Print-syntax-errors.patch >From d1d857ea0ca76f1a917382777f57871e50026df3 Mon Sep 17 00:00:00 2001 Message-Id: From: Julien Lepiller Date: Mon, 22 Nov 2021 02:54:06 +0100 Subject: [PATCH 1/2] guix: ui: Print syntax errors. * guix/ui.scm (display-syntax): New procedure. (call-with-error-handling, report-load-error): Print syntax errors. --- guix/ui.scm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/guix/ui.scm b/guix/ui.scm index bd999103ff..79aab2db84 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -69,9 +69,11 @@ (define-module (guix ui) #:use-module (srfi srfi-31) #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) + #:use-module (ice-9 exceptions) #:autoload (ice-9 ftw) (scandir) #:use-module (ice-9 match) #:use-module (ice-9 format) + #:use-module (ice-9 pretty-print) #:use-module (ice-9 regex) #:autoload (ice-9 popen) (open-pipe* close-pipe) #:autoload (system repl repl) (start-repl) @@ -315,6 +317,19 @@ (define* (display-hint message #:optional (port (current-error-port))) (texi->plain-text message)) port)) +(define %syntax-color (color BOLD GREEN)) + +(define* (display-syntax form #:optional (port (current-error-port))) + "Display FORM, an sexp, to PORT" + (define colorize + (if (color-output? port) + (lambda (str) + (colorize-string str %syntax-color)) + identity)) + + (display (colorize (G_ "in form: ")) port) + (pretty-print form port)) + (define* (report-unbound-variable-error args #:key frame) "Return the given unbound-variable error, where ARGS is the list of 'throw' arguments." @@ -398,6 +413,9 @@ (define* (report-load-error file args #:optional frame) (formatted-message-arguments obj))) (else (report-error (G_ "exception thrown: ~s~%") obj))) + (when (syntax-error? obj) + (let ((form (or (syntax-error-subform obj) (syntax-error-form obj)))) + (display-syntax form))) (when (fix-hint? obj) (display-hint (condition-fix-hint obj)))) ((key args ...) @@ -801,6 +819,9 @@ (define (call-with-error-handling thunk) (and (error-location? c) (error-location c)) (gettext (formatted-message-string c) %gettext-domain) (formatted-message-arguments c)) + (when (syntax-error? c) + (let ((form (or (syntax-error-subform c) (syntax-error-form c)))) + (display-syntax form))) (when (fix-hint? c) (display-hint (condition-fix-hint c))) (exit 1)) @@ -826,6 +847,9 @@ (define (call-with-error-handling thunk) (report-error (and (error-location? c) (error-location c)) (G_ "~a~%") (gettext (condition-message c) %gettext-domain)) + (when (syntax-error? c) + (let ((form (or (syntax-error-subform c) (syntax-error-form c)))) + (display-syntax form))) (when (fix-hint? c) (display-hint (condition-fix-hint c))) (exit 1))) -- 2.33.1 --MP_/O=5syjF3.pIA+c2Heao74c0 Content-Type: text/x-patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=0002-guix-records-Improve-error-reporting.patch =46rom 2eebd1113a40fc6e7018975d3696546de584e4a0 Mon Sep 17 00:00:00 2001 Message-Id: <2eebd1113a40fc6e7018975d3696546de584e4a0.1637548566.git.julien= @lepiller.eu> In-Reply-To: References: From: Julien Lepiller Date: Sun, 31 Oct 2021 02:58:14 +0100 Subject: [PATCH 2/2] 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..eeb5908844 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 exceptions) #: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))) + (form 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 (G_ "invalid field specifier."))) + (&syntax (form form) (subform (syntax->datum #'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 (G_ "invalid field name."))) + (&syntax (form form) (subform (map syntax->datum #'(fiel= d ...)))) + (&error-location (location location))))) + ((field) ;a list with one element + (raise-exception + (condition + (&message (message (G_ "missing value in field specifier= ."))) + (&syntax (form form) (subform (syntax->datum #'weird))) + (&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."))) + (&syntax (form form) (subform (syntax->datum #'weird))) + (&error-location (location location)) + (&fix-hint (hint (format #f (G_ "~a values were associat= ed with \ +field `~a'. Perhaps the additional values were intended to be other field= \ +specifiers. This usually indicates missing or misplaced parenthesis.") + (length #'(value ...)) + (syntax->datum #'field))))))) + (field ;not a list + (raise-exception + (condition + (&message (message (G_ "invalid field specifier."))) + (&syntax (form form) (subform (syntax->datum #'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_/O=5syjF3.pIA+c2Heao74c0-- From debbugs-submit-bounces@debbugs.gnu.org Sun Jul 17 02:23:57 2022 Received: (at 49671) by debbugs.gnu.org; 17 Jul 2022 06:23:57 +0000 Received: from localhost ([127.0.0.1]:46565 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oCxh3-00076P-9O for submit@debbugs.gnu.org; Sun, 17 Jul 2022 02:23:57 -0400 Received: from lepiller.eu ([89.234.186.109]:44430) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oCxgw-000769-4Y for 49671@debbugs.gnu.org; Sun, 17 Jul 2022 02:23:51 -0400 Received: from lepiller.eu (localhost [127.0.0.1]) by lepiller.eu (OpenSMTPD) with ESMTP id e4158c5d for <49671@debbugs.gnu.org>; Sun, 17 Jul 2022 06:23:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=lepiller.eu; h=date:from :to:subject:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; s=dkim; bh=FiHbgNJe6Sam wDZI/Mke0BsHdqsWtI3KH2+YyB0h70U=; b=g67ai+OuXJCiTQCPF/aewt/3jN2r qD+oyMr9G7B/3GFHH05RGVV7mfsUX9TCisXyeCoM7QMpv72LpZ1kv4ApKFm3CI7h Ioha4ODZ5BV0ye6qf9zc969Gm/o3Vdivy4VkP9SzXvv4+oFrhJlaZN+e4ETOb4vD m1daLemwga6eA2XJXbGNM2hf7mhgyQ8l2RHRG3n95FUXickm56ElE/99IqEZkkG2 W7BNvdbNVH1yV26RjVj7ejw6ycUOQZXr4h8uAU7F5+TvzeKgEaEb+sG+XnkoKuSS 0tBHTR8sjk55mzlnPYn/QMSsNFfr0ls/rW0noQ7NkmnLvq1qD5FFKDiHKg== Received: by lepiller.eu (OpenSMTPD) with ESMTPSA id 03f23e40 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for <49671@debbugs.gnu.org>; Sun, 17 Jul 2022 06:23:42 +0000 (UTC) Date: Sun, 17 Jul 2022 08:23:39 +0200 From: Julien Lepiller To: 49671@debbugs.gnu.org Subject: Re: [bug#49671] [PATCH v3] guix: records: Improve error reporting. Message-ID: <20220717082339.665a7385@sybil.lepiller.eu> In-Reply-To: <20211122034022.152daf55@tachikoma.lepiller.eu> References: <20210721014047.3878a0c7@tachikoma.lepiller.eu> <20211031030635.520a3c6c@tachikoma.lepiller.eu> <20211122034022.152daf55@tachikoma.lepiller.eu> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 49671 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi Guix! A few months have passed without comment. I don't feel confident enough to change Guix internals without comments. What are your thoughts on this? Le Mon, 22 Nov 2021 03:40:22 +0100, Julien Lepiller a =C3=A9crit : > Here is another improvement compared to v2. This time there are two > patches: the first adds support for &syntax in (guix ui), and will > print something like >=20 > in form: >=20 > where "in form" is in green. >=20 > The second patch is very similar to v2, but will now also raise a > &syntax condition, so it can be pretty-printed. The previous issue > where I printed # is fixed, I simply forgot a > syntax->datum. >=20 > WDYT?